Cheap Shared Hosting

Tuesday, March 18, 2008

Another VI tip - using buffers

VI lets you use buffers to quickly copy and save chunks of text. You can think of them as being sort of like the clipboard that you copy to when you highlight some text in Word or other such programs - except that you have many, many more clipboards at your disposal.

Here's how it works. In VI, highlight some text that you want to copy - hit v and then move the cursor around to highlight the text. Then decide what buffer you want to copy it to. The buffers are identified by a letter - so let's say you wanted to copy some text to the "h" buffer - you would type the following (with the text highlighted) "hy which "yanks" that text into the buffer.

You could then paste the contents of that buffer with "hp

The contents of the buffers persist until something replaces them - which makes them a great place to store those little snippets of text you use a lot.

And in reference to my earlier post about using macros, you can even use buffers within a macro! This can be quite handy if you using a macro to make repetitive changes across a large number of files. You can paste the updated text from a buffer - and if for some reason you need to change the text that's being inserted, you can copy the new text t the buffer and continue, without having to re-record the macro.

No comments: