The Ultimate VIM Cheat Sheet and Beginner’s Guide
VIM is a legendary text editor favored by power users, developers, and sysadmins for its speed, efficiency, and keyboard-driven workflow. If you’ve ever felt lost in its modal editing, you’re not alone—but once you learn its basics, VIM becomes an incredibly powerful tool.
This article offers a compact yet comprehensive cheat sheet, plus extra tips, comparisons, and visual explanations to get you fluent with VIM quickly.
Check out the Git Gist for this to get the latest updates!
Navigation Basics
h
: Move cursor leftj
: Move cursor downk
: Move cursor upl
: Move cursor right0
or^
: Move to beginning of the line$
: Move to end of the linegg
: Move to beginning of the fileG
: Move to end of the file:n
: Move to line numbern
Entering Insert Mode
i
: Insert before the cursora
: Insert after the cursorI
: Insert at the start of the lineA
: Insert at the end of the lineo
: Open a new line belowO
: Open a new line above
Editing Text
x
: Delete character under the cursordd
: Delete current lineD
: Delete from cursor to end of lineyy
: Yank (copy) current linep
: Paste after the cursorP
: Paste before the cursoru
: Undo last changeCtrl + r
: Redo undone changer<char>
: Replace a single character with<char>
cw
: Change the current wordcc
: Change (replace) entire line
Visual Mode
VIM has three types of visual mode, useful for selecting and manipulating blocks of text.
v
: Enter character-wise visual modeV
: Enter line-wise visual modeCtrl + v
: Enter block-wise visual mode (great for columns or rectangular text)>
: Indent selection<
: Outdent selectiony
: Yank selected textd
: Delete selected text~
: Toggle case of selected text
Searching and Replacing
/pattern
: Search forward forpattern
?pattern
: Search backward forpattern
n
: Jump to next matchN
: Jump to previous match:%s/old/new/g
: Replace all occurrences ofold
withnew
in the file:noh
: Clear search highlights
Saving and Quitting
:w
: Save:q
: Quit:wq
or:x
: Save and quit:q!
: Force quit without savingZZ
: Save and quit (shortcut)
File and Buffer Management
:e filename
: Open a file:bn
: Next buffer:bp
: Previous buffer:bd
: Close (delete) buffer:ls
or:buffers
: List open buffers:sp filename
: Open file in horizontal split:vsp filename
: Open file in vertical split
Window Management
Ctrl + w, w
: Switch between windowsCtrl + w, h/j/k/l
: Move focus to left/down/up/right windowCtrl + w, s
: Split window horizontallyCtrl + w, v
: Split window verticallyCtrl + w, q
: Close current windowCtrl + w, =
: Equalize split sizes
Miscellaneous Essentials
.
: Repeat the last command/changeCtrl + g
: Show file info (line, column, path)Ctrl + c
: Abort current commandCtrl + o
: Execute one normal command from insert mode, then returnCtrl + r
: Redo:set number
: Show line numbers:syntax on
: Enable syntax highlighting:set paste
: Enable paste mode (avoids auto-indent issues)
How to Clear a File in VIM
To wipe a file’s contents:
- Open the file in VIM:
vim filename
- Type
gg
to go to the top. - Press
dG
— deletes from current position to end of file.
Then save with :w
or :wq
.
How to Indent Multiple Lines in VIM
Option 1: Visual Line Mode
- Move to the first line
- Press
V
to enter visual line mode - Move cursor to select more lines (
j
) - Press
>
to indent (or<
to outdent) - Press
Esc
to exit
Option 2: Visual Block Mode
- Move to the column to begin indenting
- Press
Ctrl + v
to enter visual block mode - Use
j
to go down and select block - Press
>
to indent - Press
Esc
to exit
Interactive Learning with vimtutor
If you’re new to VIM, there’s nothing quite like hands‑on practice. To launch the built‑in tutorial, simply run this in your terminal:
vimtutor
What you’ll get:
- Step‑by‑step lessons covering modes, motion, editing, and more.
- Practice exercises built right into VIM—no additional setup required.
- A playground buffer you can experiment in; your real files stay safe.
Spend 20—30 minutes here and you’ll internalize the basics far faster than by reading alone.
Comparing VIM vs Emacs
The VIM vs Emacs debate has raged for decades. Here’s a quick breakdown:
Feature | VIM | Emacs |
---|---|---|
Modal Editing | Yes (Normal, Insert, Visual) | No (context-sensitive editing) |
Startup Time | Very fast | Generally slower |
Learning Curve | Steep at first | Also steep but different |
Extensibility | Plugins, Vimscript, Lua | Full programming language (Elisp) |
Configuration | .vimrc , plugins | .emacs , .emacs.d/ |
Ideal Use Case | Quick edits, terminal work | Full IDE replacement |
Community | Very large and active | Also strong, especially among academics |
Mouse Usage | Minimal or none | Fully supported |
Verdict:
- Choose VIM if you love keyboard-centric workflows, speed, and working from the terminal.
- Choose Emacs if you want to treat your editor like an operating system and love extreme customization.
Conclusion
VIM can feel like a boss battle at first, but with practice, it becomes one of the most fluid and powerful editing environments available. This cheat sheet gives you the most essential keys to get started and build muscle memory.
Whether you’re editing config files, writing code, or managing content from the terminal, VIM rewards mastery like few other tools do. And if you’re just starting? Bookmark this, practice often, and embrace the hjkl
!
Happy editing — and may your fingers never leave the home row.