VI Cheat Sheet
A complete reference of VI editor commands with examples and usage instructions. Find the command just using the search bar.
h
NavigationMove cursor left
Syntax:
h
Examples:
h
Move one character to the left5h
Move five characters to the leftNotes:
Basic cursor movement command
j
NavigationMove cursor down
Syntax:
j
Examples:
j
Move one line down10j
Move ten lines downNotes:
Basic cursor movement command
k
NavigationMove cursor up
Syntax:
k
Examples:
k
Move one line up3k
Move three lines upNotes:
Basic cursor movement command
l
NavigationMove cursor right
Syntax:
l
Examples:
l
Move one character to the right7l
Move seven characters to the rightNotes:
Basic cursor movement command
w
NavigationMove to beginning of next word
Syntax:
w
Examples:
w
Move to next word3w
Move forward 3 wordsNotes:
Stops at punctuation
b
NavigationMove to beginning of previous word
Syntax:
b
Examples:
b
Move to previous word2b
Move back 2 wordsNotes:
Stops at punctuation
e
NavigationMove to end of current word
Syntax:
e
Examples:
e
Move to end of word4e
Move to end of 4th word aheadNotes:
Useful for selecting to end of word
0
NavigationMove to beginning of line
Syntax:
0
Examples:
0
Move to start of current lineNotes:
Goes to column 0
$
NavigationMove to end of line
Syntax:
$
Examples:
$
Move to end of current line3$
Move to end of line 3 lines downNotes:
Useful for line editing
gg
NavigationGo to first line of file
Syntax:
gg
Examples:
gg
Go to beginning of file5gg
Go to line 5Notes:
Quick way to navigate to top
G
NavigationGo to last line of file
Syntax:
G
Examples:
G
Go to end of file10G
Go to line 10Notes:
Quick way to navigate to bottom
Ctrl+f
NavigationPage down
Syntax:
Ctrl+f
Examples:
Ctrl+f
Move one page downNotes:
Full page scroll
Ctrl+b
NavigationPage up
Syntax:
Ctrl+b
Examples:
Ctrl+b
Move one page upNotes:
Full page scroll
i
EditingInsert before cursor
Syntax:
i
Examples:
i
Enter insert mode before cursorNotes:
Most common way to start editing
a
EditingInsert after cursor
Syntax:
a
Examples:
a
Enter insert mode after cursorNotes:
Useful for appending
o
EditingOpen new line below
Syntax:
o
Examples:
o
Create new line below and enter insert modeNotes:
Creates line and enters insert mode
O
EditingOpen new line above
Syntax:
O
Examples:
O
Create new line above and enter insert modeNotes:
Creates line and enters insert mode
x
EditingDelete character under cursor
Syntax:
x
Examples:
x
Delete current character5x
Delete 5 charactersNotes:
Like pressing Delete key
X
EditingDelete character before cursor
Syntax:
X
Examples:
X
Delete character to the left3X
Delete 3 characters to the leftNotes:
Like pressing Backspace key
dd
EditingDelete entire line
Syntax:
dd
Examples:
dd
Delete current line3dd
Delete 3 lines starting from currentNotes:
Deleted lines are stored in buffer
dw
EditingDelete word
Syntax:
dw
Examples:
dw
Delete from cursor to end of word2dw
Delete 2 wordsNotes:
Deletes to end of current word
yy
EditingCopy (yank) entire line
Syntax:
yy
Examples:
yy
Copy current line5yy
Copy 5 lines starting from currentNotes:
Copied lines stored in buffer
yw
EditingCopy word
Syntax:
yw
Examples:
yw
Copy current word3yw
Copy 3 wordsNotes:
Copies from cursor to end of word
p
EditingPaste after cursor
Syntax:
p
Examples:
p
Paste after current position3p
Paste 3 timesNotes:
Pastes from buffer
P
EditingPaste before cursor
Syntax:
P
Examples:
P
Paste before current positionNotes:
Pastes from buffer
r
EditingReplace single character
Syntax:
r[char]
Examples:
ra
Replace current character with 'a'r5
Replace current character with '5'Notes:
Replaces only one character
R
EditingReplace mode
Syntax:
R
Examples:
R
Enter replace modeNotes:
Overwrites characters until Esc is pressed
u
EditingUndo last change
Syntax:
u
Examples:
u
Undo last edit5u
Undo last 5 changesNotes:
Can undo multiple actions
Ctrl+r
EditingRedo last undone change
Syntax:
Ctrl+r
Examples:
Ctrl+r
Redo last undone changeNotes:
Opposite of undo
/pattern
SearchSearch forward for pattern
Syntax:
/[pattern]
Examples:
/hello
Search forward for 'hello'/^start
Search for lines starting with 'start'Notes:
Use regular expressions
?pattern
SearchSearch backward for pattern
Syntax:
?[pattern]
Examples:
?hello
Search backward for 'hello'?end$
Search for lines ending with 'end'Notes:
Searches in reverse direction
n
SearchFind next occurrence
Syntax:
n
Examples:
n
Go to next search resultNotes:
Repeats last search
N
SearchFind previous occurrence
Syntax:
N
Examples:
N
Go to previous search resultNotes:
Repeats last search in reverse
:s/old/new/
SearchSubstitute (replace) text
Syntax:
:s/[old]/[new]/[flags]
Examples:
:s/old/new/
Replace first 'old' with 'new' on current line:s/old/new/g
Replace all 'old' with 'new' on current line:%s/old/new/g
Replace all 'old' with 'new' in entire file:1,10s/old/new/g
Replace in lines 1-10Notes:
Powerful find and replace feature
:w
FileSave file
Syntax:
:w [filename]
Examples:
:w
Save current file:w newfile.txt
Save as newfile.txt:w!
Force save (override readonly)Notes:
Write changes to disk
:q
FileQuit VI
Syntax:
:q
Examples:
:q
Quit if no changes:q!
Quit without savingNotes:
Exit the editor
:wq
FileSave and quit
Syntax:
:wq
Examples:
:wq
Save file and quit:wq!
Force save and quitNotes:
Common way to exit after editing
:x
FileSave and quit (only if changed)
Syntax:
:x
Examples:
:x
Save and quit if file was modifiedNotes:
More efficient than :wq for unchanged files
ZZ
FileSave and quit (normal mode)
Syntax:
ZZ
Examples:
ZZ
Save and quit from normal modeNotes:
Quick alternative to :wq
:e
FileEdit file
Syntax:
:e [filename]
Examples:
:e newfile.txt
Open newfile.txt for editing:e!
Reload current file, discarding changesNotes:
Open different file
:r
FileRead file into current buffer
Syntax:
:r [filename]
Examples:
:r file.txt
Insert contents of file.txt at cursor:r !ls
Insert output of 'ls' commandNotes:
Inserts file contents at cursor position
v
VisualStart visual mode (character-wise)
Syntax:
v
Examples:
v
Start selecting charactersNotes:
Select text character by character
V
VisualStart visual line mode
Syntax:
V
Examples:
V
Start selecting linesNotes:
Select text line by line
Ctrl+v
VisualStart visual block mode
Syntax:
Ctrl+v
Examples:
Ctrl+v
Start selecting rectangular blocksNotes:
Select rectangular areas of text
d (in visual mode)
VisualDelete selected text
Syntax:
d
Examples:
v[select]d
Select text then delete itNotes:
Works with any visual selection
y (in visual mode)
VisualCopy selected text
Syntax:
y
Examples:
v[select]y
Select text then copy itNotes:
Works with any visual selection
ciw
Text ObjectsChange inner word
Syntax:
ciw
Examples:
ciw
Delete current word and enter insert modeNotes:
Deletes word regardless of cursor position in word
di"
Text ObjectsDelete text inside quotes
Syntax:
di[delimiter]
Examples:
di"
Delete text inside double quotesdi'
Delete text inside single quotesdi(
Delete text inside parenthesesNotes:
Works with various delimiters
da"
Text ObjectsDelete around quotes (including quotes)
Syntax:
da[delimiter]
Examples:
da"
Delete text and double quotesda)
Delete text and parenthesesda{
Delete text and curly bracesNotes:
Includes the delimiters in the action
.
AdvancedRepeat last command
Syntax:
.
Examples:
.
Repeat the last editing commandNotes:
Very powerful for repetitive tasks
>>
AdvancedIndent line
Syntax:
>>
Examples:
>>
Indent current line3>>
Indent next 3 linesNotes:
Useful for code formatting
<<
AdvancedUnindent line
Syntax:
<<
Examples:
<<
Unindent current line2<<
Unindent next 2 linesNotes:
Removes indentation
J
AdvancedJoin lines
Syntax:
J
Examples:
J
Join current line with next line3J
Join next 3 linesNotes:
Removes line breaks
~
AdvancedSwitch case of character
Syntax:
~
Examples:
~
Change case of character under cursor5~
Change case of next 5 charactersNotes:
Toggles between upper and lowercase
Ctrl+n
AdvancedAuto-complete (in insert mode)
Syntax:
Ctrl+n
Examples:
Ctrl+n
Show completion suggestionsNotes:
Completes words from current file
Ctrl+p
AdvancedAuto-complete previous (in insert mode)
Syntax:
Ctrl+p
Examples:
Ctrl+p
Show previous completion suggestionsNotes:
Cycles backwards through completions
:set
AdvancedSet editor options
Syntax:
:set [option]
Examples:
:set number
Show line numbers:set nonumber
Hide line numbers:set autoindent
Enable automatic indentation:set tabstop=4
Set tab width to 4 spacesNotes:
Customizes editor behavior
VI Editor Tips & Modes
VI Modes
- Normal Mode: Default mode for navigation and commands
- Insert Mode: For typing text (enter with
i
,a
,o
) - Visual Mode: For selecting text (
v
,V
,Ctrl+v
) - Command Mode: For file operations (start with
:
) - Press
Esc
to return to Normal mode
Essential Workflow
vi filename
- Open filei
- Enter insert mode to edit- Type your content
Esc
- Return to normal mode:w
- Save file:q
- Quit (or:wq
to save and quit)
Quick Navigation
h j k l
- Left, down, up, rightw b
- Next/previous word0 $
- Beginning/end of linegg G
- Top/bottom of file
Common Mistakes
- Forgetting to press
Esc
before commands - Using
:q!
when you want to save changes - Not understanding which mode you're in
- Trying to use mouse for navigation
📚 What is Vi?
Vi (Visual Editor) is a legendary text editor that has been a cornerstone of Unix and Linux systems since 1976. Created by Bill Joy while he was a graduate student at UC Berkeley, Vi became the standard editor for Unix systems and is still widely used today. It's known for its powerful modal editing system and minimal interface that allows for incredibly efficient text manipulation.
🚀 Key Features
- ✓ Modal editing: Distinct modes for navigation, editing, and commands
- ✓ Ubiquitous: Available on virtually every Unix/Linux system
- ✓ Lightweight: Minimal memory footprint and fast startup
- ✓ Keyboard-centric: Designed for pure keyboard operation
- ✓ Powerful regex: Advanced search and replace capabilities
- ✓ Terminal-based: Works perfectly in command-line environments
💡 Why Use Vi?
- • Universal availability: Guaranteed to be on any Unix/Linux system
- • Remote editing: Perfect for SSH sessions and server administration
- • Efficiency: Extremely fast once you learn the commands
- • Stability: Rock-solid, time-tested reliability
- • Standards compliance: POSIX-compliant behavior
- • Foundation knowledge: Essential skill for system administrators
🎯 When to Use Vi?
System Administration
Editing configuration files, system scripts, and logs on servers where Vi is the only available editor
Emergency Situations
When systems are in recovery mode or minimal environments where only basic tools are available
Remote Work
SSH sessions, terminal-only environments, and low-bandwidth connections where GUI editors aren't practical
🔄 Vi vs Vim
Vi (Original)
- • Standard on all Unix systems
- • Minimal feature set
- • POSIX-compliant behavior
- • Smaller memory footprint
- • Guaranteed compatibility
Vim (Vi Improved)
- • Enhanced with modern features
- • Syntax highlighting & plugins
- • Multiple undo levels
- • Better regex support
- • More customization options
Choose Vi when: You need guaranteed compatibility or are working in minimal environments. Choose Vim when: You want modern features and enhanced editing capabilities.
🚀 Getting Started with Vi
1. Basic Commands
vi filename
to open • i
to insert • Esc
to normal mode • :wq
to save and quit
2. Essential Skills
Master the modes • Learn hjkl navigation • Practice common commands • Use this cheat sheet as reference
3. Practice Approach
Start with simple file edits • Focus on survival commands first • Gradually build muscle memory • Don't try to learn everything at once
Historical Note: Vi has been the standard Unix editor for over 45 years, making it one of the most enduring and influential text editors in computing history. Learning Vi is like mastering a fundamental tool that connects you to decades of Unix tradition! âš¡