A little cheatography

cheatsheet

Basic motions

Normal mode

KeyAction
iInsert mode
vvisual mode
h (navigate left)
j↓ (navigate down)
k↑ (navigate up)
l (navigate right)
wjump around words
ejumps to the end of the word
gejumps to the end of a word backwards
bjump around wors back words

editing

KeyAction
ddelete
cchange
yyank (copy)
ppaste
g~switch case
>shift right
<shift left
=format
.repeat the last change

Vim has the concept of special words (with letters, digits and numbers) that also include special character like ., (, {. They are called WORDs.

So for example:

this is a WORD: Iam_A_WORD(WORD)
this function call sum(2, 3) is also a WORD
this array [1, 2, 3, 42, 5] is a WORD as well

If you want to move WORD by WORD you can use the capitalized equivalents of the word by word motions (W, B, E, gE).

Multipliers

Counts are numbers which let you multiply the effect of a command.

{count}{command}

Example:

  • 2w moves the cursor 2 words forward.
  • 5j moves the cursor to 5 lines below.
  • 3; lets you go the next third occurrence of a character.
  • 2/jbb sends you to the second occurrence of jbb in a document.

In general, use {count}{motion} to multiply a motion {count} times.

Advanced motions

Normal mode

Moving around

KeyMotion
gggoes to the top of the document
{line}gggo to {line}
Ggoes all the way down to the end of the document
MTakes you to the middle of the visble screen
zzScrolls the document so that the current line is at the center of the screen
CTRL-dmoves you down half a page by scrolling the page
CTRL-umoves you up half a page by scrolling
$go to the end of the line
0go to the beginning of the line
^Line’s first character
g_Moves to the non-blank character at the end of a line
}jumps entire paragraphs downwars
{jumps entire paragraphs upwards
gdGo to the definition (of the word under the cursor)
gfGo to file (for file under the cursor)

Searching

KeyMotion
f{character}find
F{character}find backwards of the cursor
;repeat find
,repeat find backwards
t{character}Find the next occurrence of character and place cursor just before it
T{character}Find previous occurrence of character and place cursor just before it
%Will take you to the matching counterpart of the selected pair
/{pattern}Search for {pattern}
?{pattern}Search for {pattern} backwards
ngo to next match
Ngo to prevoius match

Inserting

KeyMotion
aInsert after cursor
AInsert after line
IInsert before the line
oInser new line below current line and go into insert mode
OInsert new line above current line and go into insert mode
gigo to the last place you left insert mode

linewise operators

KeyMotion
dddelete a line
ccchange a line
yyyank (copy) a line
g~~switch case of a line
>>shift line right
<<shift line left
==format line

text objects

KeyAction
diwdelete inner word
dawdelete a word
disdelete inner sentece
dasdelete a sentence
dipdelete inner paragraph
dapdelete a paragraph
di( (or: dib)delete inside parentheses
da( (or : dab)delete text inside parentheses (including the parentheses)
di{ (or: diB)delete inside braces
da{ (or: daB)delete text inside braces (including braces)
di[delete inside brackets
da[delete text inside brackets (including brackets)
di”delete inside quotes
da”delete a quoted text (including quotes)

Visual mode

KeyMotion
vgo into character-wise visual mode
Vgo into line-wise visual mode
CTRL-vgo into block-wise visual mode (selects rectangular blocks of text)
{trigger visual mode}{motion}{operator}First you specify the motion to select text, and then you apply the operator