Yanking vim commands

From Birnam Designs Wiki

Jump to: navigation, search

A few tips on using the Vim yank/put buffer from the Vim command line.

To explicitly set the default buffer:

:let @@="new buffer value"

Which can then be put in the document with p or P (before or after the cursor)

You can also use this to yank to another buffer:

:let @a="buffer a"

You can put this in the document with "ap or "aP

You can do this with the system clipboard too:

:let @*="copy to the clipboard"

Instead of string values, this also works with functions. This will yank the current working directory to the default buffer:

:let @@=getcwd()

And finally, it can be used to yank the output from a command (not the same as the return value of a function, like above, this is more like capturing stderr)

:redir @@
:set all
:redir END

This has captured the values provided by :set all and stored it to the default buffer.

Share This!
This page was last modified on 28 April 2010, at 22:58. This page has been accessed 2,038 times.