Skip to content

Instantly share code, notes, and snippets.

@zefer
Created April 10, 2012 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zefer/2349731 to your computer and use it in GitHub Desktop.
Save zefer/2349731 to your computer and use it in GitHub Desktop.
My newbie Vim cheatsheet

Enter insert mode

i    insert before character under cursor
a    insert after cursor
I    insert at beginning of current line
A    insert at end of the line
o    starts insert mode in a new line below current one
O    insert in a new line above current one

Enter insert mode & replace

ciw         ("change inner word") change word under cursor
ci"         change double-quoted string (but keep the quotes)
ci(         change text between matching parentheses, also works with brackets
cc          change whole line
c/}<ent>    change from cursor to next occurrence of }
c3/end<ent> change from cursor to third occurrence of end
cw          change word
c3w         change 3 words

Find & replace

replace on line     :s/<find>/<replace>
replace globally    :%s/<find>/<replace>//gc

Find in files

:vim /something/gj **/*.rb   search for 'something' in all subdirs. j=don't jump to first result
:cw                          open the results in a 'quick fix list'
:lvim /something/gj **/*.rb  (as above but local to current window)
:lw                          (as above but local to current window)

Move

  k
h   l     Cursor movement
  j

→    ←
/    ?    search for a pattern of text, jump to it by hitting Enter (<CR>)
*    #    search for the word under cursor
n    N    jump to the next match for the previous search
$    ^    position cursor at end of current line
f    F    position cursor on the character in the same line that matches the next keystroke
t    T    position cursor before the next character that matches the keystroke
;    ,    repeat the last f, F, t, or T
w    b    move to start of next word
W    B    move to start of next "WORD" (sequence of non-blank characters)
}    {    move down one paragraph (block of text separated by blank lines)
gg        jump to first line of document
G         jump to end of document
22G       go to line 22
:22       go to line 22

Manipulating text

cut the current line                  dd
copy the current line                 yy
paste below current line              p
paste above current line              P
remove the character under cursor     x
remove the character before cursor    X
delete the word under cursor          de
delete to the end of the line         d$

remove five lines starting here       5dd
copy five lines starting here         5yy 

indent this line                      >>
indent five lines starting here       5>>

replace mode (overtype)               r
replace with x                        rx

Copy & paste registers

copy & paste using default register   yy      p
copy & paste using register 'a'       "ayy    "ap
copy & paste using system clipboard   "+yy    "+p
copy & paste using system clipboard   "*yy    "*p

Auto complete/suggest C-p

Visual mode selection

Visual mode         v
Visual Line mode    V
Visual Block mode   <CTRL>v

Split panes

:split    new horizontal pane
:vsplit   new vertical pane
<C-w>     move next
<C-k>     move up
<C-j>     move down
<C-h>     move left
<C-l>     move right
<C-w> x   swap panes
<C-w> |   max width
<C-w> _   max height
<C-w> =   equalise sizes

Command-T

<C-CR>    open the selected file in a new split window
<C-s>     open the selected file in a new split window
<C-v>     open the selected file in a new vertical split window
<C-t>     open the selected file in a new tab

Commands

Run a command   !<command>
Open a shell    :sh

Resources

vim-revisited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment