Beginner’s Guide to Vim: A Handy Motions & Commands Cheat Sheet
Introduction
Vim is a powerful, keyboard-focused text editor that can dramatically increase your productivity—once you get the hang of its unique commands and modes. The good news? You don’t have to memorize everything right away. Start by learning the essentials, practice them regularly, and build up from there.
This cheat sheet is designed for beginners looking to learn core Vim motions and commands quickly. You’ll find everything you need to navigate files, edit text, and manage multiple buffers—without ever needing to reach for the mouse. Let’s dive in!
Vim Cheat Sheet
1. Cursor Movement
Use these single-letter commands to move around quickly in Normal mode.
- h — move left
- j — move down
- k — move up
- l — move right
- w — jump forward to start of words (punctuation considered words)
- W — jump forward by words (ignoring punctuation)
- e — jump to the end of words (punctuation considered words)
- E — jump to the end of words (ignoring punctuation)
- b — jump backward by words (punctuation considered words)
- B — jump backward by words (ignoring punctuation)
- 0 — go to the start of line
- ^ — go to the first non-blank character of line
- $ — go to the end of line
- G — “Go To” command. Prefix with a number to jump to that line (e.g., 5G to go to line 5).
Pro Tip: Prefix any cursor movement with a number to repeat it. For example, 4j moves down 4 lines.
2. Insert Mode — Inserting/Appending Text
These commands switch you into Insert mode so you can type text.
- i — start Insert mode at cursor
- I — insert at the beginning of the line
- a — append after the cursor
- A — append at the end of the line
- o — open a blank line below current line
- O — open a blank line above current line
- ea — append at the end of a word
- Esc — exit Insert mode
3. Editing
Easily modify text without leaving Normal mode.
- r — replace a single character (no Insert mode)
- J — join the next line to the current line
- cc — change (replace) an entire line
- cw — change (replace) to the end of the current word
- c$ — change (replace) to the end of the line
- s — delete character at cursor and substitute text
- S — delete line at cursor and substitute text
- xp — transpose two letters (effectively cut and paste)
- u — undo last operation
- . — repeat the last command
4. Marking Text (Visual Mode)
Visual modes let you select text before issuing a command like yank (copy) or delete.
- v — start visual mode (character-wise)
- V — start linewise visual mode
- Ctrl+v — start visual block mode
- o — move to the other end of the marked area
- O — in block mode, move to the other corner of the block
- aw — mark a word
- ab — mark a () block
- aB — mark a block
- ib — mark inner () block
- iB — mark inner block
- Esc — exit visual mode
5. Visual Commands
Apply these commands while in Visual mode.
- > — shift right (indent)
- < — shift left (un-indent)
- y — yank (copy) marked text
- d — delete marked text
- ~ — switch case of selected text
6. Cut and Paste (Yank & Delete)
These commands let you copy, cut, and paste text.
- yy — yank (copy) a line
- 2yy — yank 2 lines
- yw — yank (copy) the current word
- y$ — yank to the end of the line
- p — put (paste) the clipboard after the cursor
- P — put (paste) the clipboard before the cursor
- dd — delete (cut) a line
- dw — delete (cut) the current word
- x — delete (cut) the current character
7. Exiting
Quit and save files with these commands (entered in Command-line mode by pressing :).
- :w — write (save) the file, but don’t exit
- :wq — write (save) and quit
- :q — quit (fails if there are unsaved changes)
- :q! — quit without saving
8. Search and Replace
Boost productivity with quick search and replace.
- /pattern — search forward for “pattern”
- ?pattern — search backward for “pattern”
- n — repeat search in same direction
- N — repeat search in the opposite direction
- :%s/old/new/g — replace all instances of “old” with “new”
- :%s/old/new/gc — replace all “old” with “new” with confirmation
9. Working with Multiple Files
Manage multiple buffers (files) in Vim without leaving the editor.
- :e filename — edit a file in a new buffer
- :bnext or :bn — go to next buffer
- :bprev or :bp — go to previous buffer
- :bd — delete (close) the current buffer
- :sp filename — split window horizontally and open file
- Ctrl+w s — split windows horizontally
- Ctrl+w v — split windows vertically
- Ctrl+w w — switch between windows
- Ctrl+w q — quit a window
How to Use This Cheat Sheet Effectively
-
Practice Gradually
Try one or two new commands each day and use them actively until they become second nature. -
Stay in Normal Mode
The power of Vim lies in its modal nature. Resist the urge to stay in Insert mode; jump back to Normal mode to move and edit quickly. -
Customize Vim
Explore your~/.vimrc
orinit.vim
(for Neovim) to set up plugins, color schemes, and custom keybindings that make Vim work perfectly for you. -
Stay Curious
Vim is incredibly powerful. Keep learning advanced motions, macros, and search/replace tricks for an even more efficient workflow.
Conclusion & Next Steps
Learning Vim can feel overwhelming at first, but this cheat sheet will help you build a strong foundation. Focus on mastering the basics of movement, editing, and visual selection, and you’ll soon see how Vim’s modal approach can make you faster and more productive than ever.
Quick Action Steps
- Bookmark or print this cheat sheet and reference it while coding.
- Add new commands to your daily routine until they become automatic.
- Keep exploring advanced Vim features (like macros and registers) to further enhance your productivity.
Embrace the Vim mindset—less mouse, more keyboard—and watch your efficiency skyrocket!