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 commands. Show all posts
Showing posts with label commands. Show all posts
Wednesday, April 9, 2008
Tuesday, March 25, 2008
Piping Buffers
Say you have a buffer in Vim, and you want to run it through an external command. For the sake of example, let's say that command is sort. All you have to do is the following:
:% ! sort
or more generally
:% ! command
If you want to bring the output of a command into buffer you can do:
:r ! ls -l
or even:
:r ! cat filename | sort
:% ! sort
or more generally
:% ! command
If you want to bring the output of a command into buffer you can do:
:r ! ls -l
or even:
:r ! cat filename | sort
Subscribe to:
Posts (Atom)