Skip to content

Instantly share code, notes, and snippets.

@benaskins
Created May 24, 2010 07:19
Show Gist options
  • Save benaskins/411611 to your computer and use it in GitHub Desktop.
Save benaskins/411611 to your computer and use it in GitHub Desktop.
Learning VIM
:buffers - shows open buffers
:b <n> - switch to numbered buffer
:bd - close buffer
:o <file> - open file name
:o . - open dir, shows directory listing
:bn - next buffer
:bp - previous buffer
:split - split screen
In split window:
ctrl-w j - next window
ctrl-w k - prev window
f<char> - find character
<n>f - find nth character
; - repeat find
. - repeat prior edit
Combined these become powerful. e.g.
f,a<SPACE>
says find the comma, and add a trailing space. Then
;.
repeats the find, then repeats the replace.
The repeat action also works with find within the buffer, so:
/,
says find the comma
a<SPACE>
says add a space after
n.
says find the next comma and add a space
:s/<from>/<to> - search and replace first occurence on line
:s/<from>/<to>/g - search and replace all occurences on line
:%s/<from>/<to>/g - search and replace all occurences in file
:1,5 s/<from>/<to>/g - search and replace all occurences within range
ct<char> - replace everything up to the matching <char>
ctrl-v - visual block mode, can select a block of text, edit the first instance, then apply that edit to all selected lines
y - yank (copy)
d - delete (cut)
:1,5y - yank lines 1 through 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment