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.
Navigation Basics
- h: Move cursor left
- j: Move cursor down
- k: Move cursor up
- l: Move cursor right
- 0 or ^: Move to beginning of the line
- $: Move to end of the line
- gg: Move to beginning of the file
- G: Move to end of the file
- :n: Move to line number n
Entering Insert Mode
- i: Insert before the cursor
- a: Insert after the cursor
- I: Insert at the start of the line
- A: Insert at the end of the line
- o: Open a new line below
- O: Open a new line above
Editing Text
- x: Delete character under the cursor
- dd: Delete current line
- D: Delete from cursor to end of line
- yy: Yank (copy) current line
- p: Paste after the cursor
- P: Paste before the cursor
- u: Undo last change
- Ctrl + r: Redo undone change
- r<char>: Replace a single character with <char>
- cw: Change the current word
- cc: 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 mode
- V: Enter line-wise visual mode
- Ctrl + v: Enter block-wise visual mode (great for columns or rectangular text)
- >: Indent selection
- <: Outdent selection
- y: Yank selected text
- d: Delete selected text
- ~: Toggle case of selected text
Searching and Replacing
- /pattern: Search forward for pattern
- ?pattern: Search backward for pattern
- n: Jump to next match
- N: Jump to previous match
- :%s/old/new/g: Replace all occurrences of old with new in the file
- :noh: Clear search highlights
Saving and Quitting
- :w: Save
- :q: Quit
- :wq or :x: Save and quit
- :q!: Force quit without saving
- ZZ: 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 windows
- Ctrl + w, h/j/k/l: Move focus to left/down/up/right window
- Ctrl + w, s: Split window horizontally
- Ctrl + w, v: Split window vertically
- Ctrl + w, q: Close current window
- Ctrl + w, =: Equalize split sizes
Miscellaneous Essentials
- .: Repeat the last command/change
- Ctrl + g: Show file info (line, column, path)
- Ctrl + c: Abort current command
- Ctrl + o: Execute one normal command from insert mode, then return
- Ctrl + 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:
1. Open the file in VIM: vim filename
2. Type gg to go to the top.
3. 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
1. Move to the first line
2. Press V to enter visual line mode
3. Move cursor to select more lines (j)
4. Press > to indent (or < to outdent)
5. Press Esc to exit
Option 2: Visual Block Mode
1. Move to the column to begin indenting
2. Press Ctrl + v to enter visual block mode
3. Use j to go down and select block
4. Press > to indent
5. Press Esc to exit
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.