This cheatsheet is a quick reference for core vi commands you will actually use: navigation, editing, search, copy/paste, and file operations. It focuses on practical commands that work in basic vi (not just vim) and are essential for efficient editing in terminal-only environments.
Never feel lost in vi again!
Modes#
Esc # Back to Normal mode
i # Insert before cursor
a # Insert after cursor
I # Insert at beginning of line
A # Insert at end of line
o # Open new line below
O # Open new line above
v # Start visual character selection
V # Start visual line selection
Ctrl+v # Start visual block selection
: # Command-line modeOpen Files#
vi file.txt # Open file
vi +42 file.txt # Open file at line 42
vi +/pattern file # Open file at first match
vi . # Open file browser (if vim with netrw)
:e# # Toggle to previous file (great for quick back-and-forth edits)Movement#
h j k l # Left, down, up, right
w # Next word
b # Previous word
e # End of word
0 # Start of line
^ # First non-blank character
$ # End of line
gg # First line
G # Last line
42G # Go to line 42
Ctrl+d # Half-page down
Ctrl+u # Half-page up
% # Jump between matching (), {}, []Editing#
x # Delete character under cursor
rX # Replace one character with X
R # Enter overwrite mode (overwrites characters)
s # Substitute character and enter Insert mode
cw # Change word
cc # Change entire line (deletes line content and enters Insert mode)
C # Change to end of line
dw # Delete word
dd # Delete line
D # Delete to end of line
J # Join line with next line
gg=G # Auto-indent whole file
u # Undo
Ctrl+r # Redo
. # Repeat last changeCopy, Cut, Paste#
yw # Yank word
yy # Yank line
y$ # Yank to end of line
dw # Cut word
dd # Cut line
p # Paste after cursor
P # Paste before cursor
"+y # Yank to system clipboard (vim +clipboard)
"+p # Paste from system clipboardSearch#
/pattern # Search forward
/pattern\c # Search forward (force case-insensitive for this search)
/pattern\C # Search forward (force case-sensitive for this search)
?pattern # Search backward
n # Next match
N # Previous match
* # Search word under cursor forward
# # Search word under cursor backward
:set hlsearch # Highlight search matches
:set nohlsearch # Disable highlighting
:noh # Clear current highlightReplace#
:s/old/new/ # Replace first match in current line
:s/old/new/g # Replace all matches in current line
:%s/old/new/g # Replace all matches in file
:%s/old/new/gc # Replace all with confirmation
:0,$s/old/new/g # Same as :%s, explicit full-file line range
:0,$s/old/new/gc # Full-file replace with confirmation
:10,20s/old/new/g # Replace in line range
:%d # Delete entire buffer contentSave And Quit#
:w # Save
:w newname.txt # Save as
:wq # Save and quit
:x # Save and quit (only if modified)
:q # Quit (fails if modified)
:q! # Quit without saving
ZZ # Save and quit (Normal mode)
ZQ # Quit without saving (Normal mode)Multi-File And Buffers#
Important
Multi-file/buffer features require full vim; basic vi may not support them.
:e other.txt # Edit another file
:ls # List buffers
:bnext # Next buffer
:bprev # Previous buffer
:b 3 # Jump to buffer 3
:bd # Delete current bufferUseful Settings#
:set number # Show line numbers
:set relativenumber # Show relative line numbers
:set paste # Paste without auto-indent side effects
:set nopaste # Disable paste mode
:set expandtab # Use spaces instead of tabs
:set tabstop=4 # Visual tab width
:set shiftwidth=4 # Indent width for >> and <<
:set list # Show invisible characters (tabs/trailing spaces)
:set nolist # Hide invisible characters
:set ignorecase # Case-insensitive search
:set smartcase # Smart case-sensitive searchFast Everyday Flow#
vi file.txt # Open file
/pattern # Find where to edit
ciwnew_text # Change current word
. # Repeat last change (huge speed boost)
A; # Append at end of line
:w # Save
:q # QuitQuick Escape Route#
When you are stuck and just want to get out safely:
Esc # Return to Normal mode
:q! # Quit without saving
vi file.txt # Re-open cleanly and try againTips#
- If you feel lost, press Esc twice and continue from Normal mode.
- Use counts to speed up actions: 5j, 3dd, 10x.
- Prefer :w often; use :q! only when you really want to discard changes.
- On minimal systems, vi may not be full vim, so some features can be unavailable.
