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.

Monday, November 10, 2008

getting colder?

Another gem (from pov of those of us who grep a lot) found in VIM documentation:

:help :colder

At first I thought that is another wit command but then realized that the name fits to :cnext and :cprev commands.

Snip from VIM documentation:

So far has been assumed that there is only one list of errors. Actually the
ten last used lists are remembered. When starting a new list, the previous
ones are automatically kept.

And the two commands are :colder (to go to previous results) and :cnewer (to go back to newer results).

P.S. "List of errors" is used in VIM originally for :make. Results of :grep are also interpreted as list of errors, what promotes grep into rank of compiler (:

Thursday, November 06, 2008

VIM tips exchange on Slashdot


Flamewars Alert. This is Slashdot after all.