Copy and paste in vi + some other tips

4/9/2009 — Leave a comment

vim-editor_logo-300x300

I use vi a lot at work.  It really became a lot more useful when I figured out how to copy and paste blocks of code.

All of these are done in command mode:

shift-v =  select a line
ctrl-v = select a rectangle
Y = yank selection to buffer
P = paste from buffer before cursor
p = paste from buffer after cursor position
dd = delete a line (this also moves the line to the buffer, so you can still paste it)

Here are some other handy ones:

u = convert a selection to lowercase
u = undo previous action (if nothing is selected)
ctrl-R = redo an action
gg = go to the top of the document
G = go to the end of the document
###gg = go to line number ###
:%s/blah/whee/gc = replace “blah” with “whee” globally with confirmation
:%r~/whee.txt = insert text into the current document from a file (~ = your home directory)

wvpv

what others do with talent, I do with obstinate fixation

No Comments

Be the first to start the conversation.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>