vim and :g

Note: This entry has been restored from old archives.

So many things, like vim, are a land of constant discovery. Just now I have devised:

:g/$/exec "s/$/!".line(".")."|"

What it does is append to every line the string ! | – which will look absurd to most people, but it is incredibly useful for me. There are probably a billion other ways to do the same thing…

Munged from an example on vim.org that inserts line numbers at the start of the line:

:g/^/exec "s/^/".strpart(line(".")."    ",0,4)