M
MeshWorld.
Cheatsheet Vim Neovim Terminal Linux Text Editor Developer Tools 8 min read

Vim Cheat Sheet: Modes, Navigation, Editing & Config

By Vishnu Damwala

The one thing to understand first

Vim has modes. Most editors have one mode where keys type characters. Vim has several, and which mode you’re in changes what every key does.

The most important: Esc always returns you to Normal mode — where keys are commands, not characters.


Quick reference tables

Modes

KeyModeWhat you can do
(default)NormalNavigate, run commands
iInsertType text (before cursor)
aInsertType text (after cursor)
AInsertType at end of line
oInsertOpen new line below, type
OInsertOpen new line above, type
vVisualSelect characters
VVisual LineSelect whole lines
Ctrl+vVisual BlockSelect a column block
:CommandRun Ex commands (:w, :q, etc.)
/SearchForward search
?SearchBackward search

Exiting Vim

CommandWhat it does
:qQuit (only if no unsaved changes)
:q!Force quit, discard changes
:wSave without quitting
:wqSave and quit
:xSave and quit (same as :wq)
ZZSave and quit (shortcut)
ZQQuit without saving (shortcut)
KeyMovement
h j k lLeft · Down · Up · Right
wNext word start
WNext WORD start (space-delimited)
bPrevious word start
eEnd of current/next word
0Start of line
^First non-blank character of line
$End of line
ggFirst line of file
GLast line of file
5G or :5Go to line 5
Ctrl+dScroll down half page
Ctrl+uScroll up half page
Ctrl+fScroll down full page
Ctrl+bScroll up full page
zzCenter cursor on screen
%Jump to matching bracket
{ }Jump between paragraphs/blank lines

Editing — Normal mode

KeyWhat it does
xDelete character under cursor
XDelete character before cursor
ddDelete (cut) entire line
5ddDelete 5 lines
dwDelete to end of word
d$ or DDelete to end of line
d0Delete to start of line
yyYank (copy) line
5yyYank 5 lines
ywYank word
pPaste after cursor
PPaste before cursor
uUndo
Ctrl+rRedo
rReplace single character
REnter replace mode (overwrite)
ccChange (delete) entire line, enter Insert
cwChange to end of word
c$ or CChange to end of line
~Toggle case of character
guLowercase selection (visual)
gUUppercase selection (visual)
.Repeat last change
JJoin current line with next

Search & replace

CommandWhat it does
/patternSearch forward
?patternSearch backward
nNext match
NPrevious match
*Search for word under cursor (forward)
#Search for word under cursor (backward)
:%s/old/new/gReplace all occurrences in file
:%s/old/new/gcReplace all, confirm each
:5,10s/old/new/gReplace in lines 5–10
:nohClear search highlight

Visual mode

KeyWhat it does
vStart character selection
VStart line selection
Ctrl+vStart block/column selection
oMove to other end of selection
yYank selection
dDelete selection
cDelete selection, enter Insert
>Indent selection
<Unindent selection
~Toggle case
uLowercase
UUppercase

Split panes & tabs

CommandWhat it does
:spHorizontal split (same file)
:sp file.jsHorizontal split with another file
:vspVertical split
:vsp file.jsVertical split with another file
Ctrl+w h/j/k/lMove between panes
Ctrl+w =Make all panes equal size
Ctrl+w _Maximize height of current pane
Ctrl+w |Maximize width of current pane
:qClose current pane
:tabnewOpen new tab
:tabnew file.jsOpen file in new tab
gtNext tab
gTPrevious tab
:tabcloseClose current tab

Marks & jumps

CommandWhat it does
maSet mark a at cursor
`aJump to exact position of mark a
'aJump to line of mark a
Ctrl+oJump back (previous position)
Ctrl+iJump forward
''Jump to position before last jump

Macros

CommandWhat it does
qaStart recording macro into register a
qStop recording
@aPlay macro a
5@aPlay macro a 5 times
@@Repeat last macro

Detailed sections

The mental model

Think of Vim commands as sentences: verb + motion or verb + text object.

  • dwdelete word
  • ci"change inside (quotes)
  • ya(yank around ( (parentheses, including them)
  • vipvisual select inner paragraph

Once you learn the verbs (d, c, y, v) and motions (w, b, e, 0, $) and text objects (iw, aw, i", a(, ip), you can combine them freely.

Text objects — the secret weapon

These work with any verb. i = inner (excluding delimiters), a = around (including delimiters).

Text objectSelects
iwInner word
awA word (including trailing space)
i"Inside double quotes
a"Double quotes including the quotes
i'Inside single quotes
i( or ibInside parentheses
a( or abParentheses including them
i{ or iBInside curly braces
itInside HTML/XML tag
ipInner paragraph

Examples:

ci"   →  delete inside quotes, start typing
da{   →  delete a whole { block } including braces
yip   →  copy entire paragraph

The dot command — your best friend

. repeats the last change. This is incredibly powerful.

Example: add a semicolon to the end of multiple lines.

A;<Esc>      →  go to end of line, type ;, escape
j.           →  go down, repeat
j.           →  go down, repeat

Search and replace patterns

" Replace all 'foo' with 'bar' in file
:%s/foo/bar/g

" Replace with confirmation
:%s/foo/bar/gc

" Case-insensitive replace
:%s/foo/bar/gi

" Replace only in a visual selection (select first with V, then :)
:'<,'>s/foo/bar/g

" Delete all blank lines
:g/^$/d

" Delete all lines containing 'TODO'
:g/TODO/d

Macros — automate repetitive edits

Example: add quotes around each word on a line.

  1. Position cursor on first word
  2. qa — start recording into register a
  3. bi"<Esc>ea"<Esc>w — add quotes, move to next word
  4. q — stop recording
  5. 5@a — repeat 5 more times

A minimal .vimrc to get started

" Line numbers
set number
set relativenumber

" Indentation
set tabstop=2
set shiftwidth=2
set expandtab
set autoindent

" Search
set hlsearch
set incsearch
set ignorecase
set smartcase

" UI
set cursorline
set scrolloff=8
set colorcolumn=80
syntax enable

" Mouse support
set mouse=a

" No swap files
set noswapfile

" Better backspace
set backspace=indent,eol,start

Save as ~/.vimrc and restart Vim.

Just need to get out? How to Exit Vim, Vi, and Nano.