Today I had a friend ask me, "is there a way to load every line matching a pattern into a single register?" This lead me to look into a way to append to a register. I've come to find out that yanking something into a register using a capital rather than lowercase letter appends instead of overwriting the register. From there, it was just a matter of using the global command to invoke a yank on all the matches. Here's the result.
:%g/.*foo.*/normal "Ayy/
Note that `A and `a share the same register. So you can simply put using "ap (as usual). Another neat trick is a quick way to clear a register. Registers often persist among sessions (depending on your Vim setup). You can clear any register a to z as follows.
:let @a=@_
I knew there was a use for the blackhole register ;-).
Showing posts with label append. Show all posts
Showing posts with label append. Show all posts
Wednesday, April 9, 2008
Subscribe to:
Posts (Atom)