Content
    Modes

vim

Modes

KeyMode
iInsert at current cursor position
IInsert at beginning of line
aInsert after current cursor position
AInsert at end of line
oInsert at new line after cursor position
OInsert at new line before cursor position
rReplace char at current cursor position
RReplace (overwrite) mode
ESCNormal

Vim as a Language

[count]operation[modifier|count]{motion}

Operation (Verbs)

CommandMeaning
ddelete
cchange
yyank (copy)
vvisually select (V for line)

Modifiers

ModifierMeaning
iinside
aaround
numbere.g.: 1, 2, 10
tsearch (stop before it)
fsearch (stop on it)
/find regex

Motion (Nouns)

NounMeaning
wword
s or )sentence
p or }paragraph
ttag (HTML/XML)
bblock (programming)

These key can also be used for navigation.

By Line or Character

KeyMovement
hleft
jdown
kup
lright
^ or 0beginning of line
$end of line

move by line or char

Hint: j looks like an arrow pointing down

By Word

KeysMovement
wnext word
Wnext word, don’t stop at punctuation
bprevious word
Bprevious word, don’t stop at punctuation

By Page

KeysMovement
ctl-bpage up
ctl-fpage down

Begin and End of Document

KeysMovement
gg or :1first line
G or :$last line

Go to Line

KeysMovement
<line-no>gg, <line-no>G or :<line-no>go to line

Editing

Cut / Delete

KeyAction
x or dlDelete (cut) char at cursor
X or dhDelete (cut) char before cursor
dwDelete (cut) word at cursor
dbDelete (cut) word before cursor
ddDelete (cut) current line
D or d$Delete (cut) to end of line
d0Delete (cut) to beginning of line

Copy / Yank

KeyAction
ywYank (copy) word at cursor
ybYank (copy) word before cursor
yyCopy line

Paste / Put

KeyAction
pPaste after cursor
PPaste before cursor

Change Text

KeyAction
c<motion>Change text
CChange text until end of line
ccChange entire line

Join Lines

KeyAction
JJoin lines with spaces added
gJJoin lines without additional spaces

Change Case

KeyAction
gU<motion>To upper case
gu<motion>To lower case
g~<motion>Toggle case
~Toggle case of character at cursor

Registers

  • Unnamed (default): ""
    • holds text from last d, c, s, x and y
  • Numbered: "0 - "9
    • "0 holds last yanked (y) text
    • "1 holds last cut (d) or changed (c) text
    • "1 shifts with each d and c
  • Named: "a - "z
    • User upper-case ("A - "Z to append to the content of the register)
  • Black-hole: "_
    • doesn’t store removed text in a register
[count][register]operation

or

[register][count]operation
KeyAction
:reg [register(s)]Show content of listed registers. Show all if no register provided

Search and Replace

Search on Line

KeyAction
f<char>Search forward on line
F<char>Search backwards on line
t<char>Go forward to stopping before char
T<char>Go backward to stopping after char
;Continue search in original direction
,Continue search in opposite direction

These commands are considered as motions and can be used with operations like d, c and y.

Search in Document

KeyAction
/<word>Search forwards for word
?<word>Search backward for word
*Search forward for word under cursor
#Search backward for word under cursor
nGo to next occurrence in search direction
NGo to previous occurrence in search direction

Replace

General command syntax:

:[range]/<old>/<new>/[flags]

The separator / can be replaced by another symbol (e.g. # or |)

Range:

  • <number>: line with number
  • <number-1>,<number-2>: from line number-1 to number-2
  • /<pattern-1>/,/<pattern-2>/: from match of pattern-1 to pattern-2
  • .: current line
  • $: last line
  • % or 1,$: entire file

Range variants can be combined

Flags:

  • g: global (all occurrences in line)
  • c: confirm each replacement
  • i: ignore case

Text Objects

  • Word: w (or W with punctuation)
  • Sentence: s
  • Paragraph: p
  • Block: b
  • Tag: t
  • Various delimiters: {, ], ), <, ",…

Include or exclude delimiter

  • Apply operator to object including separators: <operator>a<object>
  • Apply operator to object without separators: <operator>i<object>

Examples:

  • daw: Delete A Word
  • ciw: Change Inner Word (without delimiter)

Visual Mode

KeyAction
vCharacterwise visual mode
VLinewise visual mode
ctl-vBlockwise visual mode
gvSwitch to visual mode with last selection
oSwitch to opposite side of selection
OSwitch to opposite side of selection on same line (in block selection mode)

Buffers

KeyAction
:buffers, :b or :lsList open buffers
:b <number> or :b <name>Show buffer in current window
:bnShow next buffer
:bpShow previous buffer
:bfShow first buffer
:blShow last buffer
:badd <name>Create new buffer
:bd <number> or :bd <name>Close buffer
:wallSave all buffers
:qall!Close all buffers without saving
:bufdo <cmd>Run command on each open buffer

Windows

KeyAction
:sp [file] or <ctl>-w sSplit window horizontally
:vs [file] or <ctl>-w vSplit window vertically
<ctl>-w <ctl>-wChange to next window
:q or <ctl>-w qClose window
:only, :on or <ctl>-w oClose all other windows
:ba or :ballOpen all buffers in separate windows
:windo <cmd>Run command on each windows
KeyAction
<ctl>-w hNavigate left to window
<ctl>-w jNavigate down to window
<ctl>-w kNavigate up to window
<ctl>-w lNavigate right to window

Move Windows

KeyAction
<ctl>-w HMove window to left
<ctl>-w JMove window down
<ctl>-w KMove window up
<ctl>-w LMove window to right

Resize Windows

  • <ctl>-w +: Increase window size vertically
  • <ctl>-w -: Increase window size vertically
  • <ctl>-w -: Decrease window size vertically
  • <ctl>-w <: Increase window size horizontally
  • <ctl>-w >: Decrease window size horizontally
  • <ctl>-w _: Maximize height of window
  • <ctl>-w |: Maximize width of window
  • <ctl>-w =: Make all windows the same size

Macros

KeyAction
q<register>Record macro and save it in the register
qStop recording macro (in normal mode)
@<register>Apply macro in the register
@Apply last executed macro

Macros can be appended by using capital register names

Apply Macro on Range of Lines

Use ranges as in the substitute command and provide the register with the macro to apply:

:<range-start>,<range-end>normal @<reg-name>`

Considerations for Macros

  1. Start always at same position (i.e. beginning of line 0)
  2. Record operations
  3. Position cursor at sensible position (i.e. next line j)

Various

KeyAction
.Repeat previous command
zzShift current line to middle of screen
<tab> or <ctrl>-dAutocompletion for commands
uUndo last command
<ctrl>-rRedo last command

Help and Documentation

CommandAction
:h [command]Get help (without command: general help)
:h {subject}Get help for a subject
<ctrl>-]Follow link
<ctrl>-w <ctrl>-wSwitch between help and editor window

See Also

Learn Vim Progressively Learn Vim For the Last Time



  • Category

  • Programming

  • Tags

  • Tools
    Cheat Sheet
    Unix
    Linux

  • Created

  • 4. April 2019


  • Modified

  • 9. September 2025