Thursday, November 20, 2008

how to not loose vim stdin buffer after opening a file

I often use VIM instead of "less" as pager. Usually in a way like "diff -u ... | vim -R -c 'set syntax=diff' -" (for what I actually have a shell alias).

The one thing was annoying me for quite some time: when vim reads input from stdin, it does create unnamed buffer where to the content is loaded. Unnamed means that as soon as I open in the same vim another file, the stdin input is lost and I do not know of a way to recover it: it doesn't show up in ":ls" anymore.

I have tried to do ":w" yet that created a new file - but the buffer with stdin still remained unnamed and was still replaced by first open file.

After some search I have found a nice command - ":sav" (:help :saveas).

Unlike originally intended for ranges ":w" command, the ":sav" operates on files and thus has enough authority to change buffer name, making stdin buffer persistent.

P.S. "vim -" is described under ":help read-stdin" and ":help --" (two minuses). Though the description is quite shallow.

No comments: