Output the neovim terminal to a file

Hello nvim users!

Is there any way to output the terminal commands and messages to a file ?

I’m using nvim’s terminal so much and I’d like to save all of that to a file to reuse it later.

For the other example to save the command’s inputs/outputs to a file, there is a linux command like a script and I tried it. But that command made a weird and unuseful output in my environment unfortunately.

The thing what I hope is to output the same thing displayed in nvim’s terminal, so could everyone has a good idea?

Will sending the output to a register and then paste that into a file work for you ?

How about executing :w filename in the terminal buffer?

Wow, never thought about that…

I tried and it doesn’t work, as soon as you type any character it closes automatically

Thank you, @igrep

Your brief suggestion fixed my annoying stuffs perfectly.

Now I’m in hassle-free state.

Thanks a lot.

1 Like

@igrep
My apologies for my bad skills.

After your reply, I’ve tried to append the nvim’s terminal messages to the file already opened.

But :w <opened-file.txt> didn’t work well with the error message of followings:

E139: File is loaded in another buffer

It seems that the overwritting to another buffer is not allowed.

Is there any good idea to fix this?

When the <opened-file.txt> is not opened in vim, appending is working well.

According to :help :w_a:

:[range]w[rite][!] [++opt] >> {file}
			Append the specified lines to {file}.  '!' forces the
			write even if file does not exist.

So :w >> filename would work.

Update: Sorry, I’ve misread. I’m not sure how to avoid E139!
See the next reply!

Sorry, I’ve misread. Then, how about :w !cat >> opened.txt?

Ref. :help :w_c

Update: Use cat instead of tee not to print the stdin to stdout.

1 Like

Thank you so much !

:w !tee >> opened.txt is nothing but perfect.

I appreciate your incredible effort.

1 Like