Essential Vim Commands and Shell Vi Mode
A practical guide to the most commonly used vim commands and shell vi mode. This covers the 20% of commands you’ll use 80% of the time.
Setting Up Vi Mode in Shell
Zsh
Add to ~/.zshrc:
| |
Bash
Add to ~/.bashrc:
| |
Apply and Test
| |
Shell Vi Mode - Essential Commands
The Basics
| Command | Action |
|---|---|
ESC | Enter command mode |
i | Enter insert mode |
a | Insert after cursor |
A | Insert at end of line |
Navigation
| Command | Action |
|---|---|
h, j, k, l | Left, down, up, right |
w | Next word |
b | Previous word |
0 | Start of line |
$ | End of line |
Editing
| Command | Action |
|---|---|
x | Delete character |
dd | Delete line |
D | Delete to end of line |
cc | Delete line and insert |
u | Undo |
History & Search
| Command | Action |
|---|---|
k / j | Previous / next in history |
/text | Search history forward |
n | Next search result |
Essential Vim Commands
Opening Files
| |
The Two Modes You Need
ESC - Normal mode (navigate and command)
i - Insert mode (type text)
Saving and Quitting
| Command | Action |
|---|---|
:w | Save |
:q | Quit |
:wq or ZZ | Save and quit |
:q! | Quit without saving |
Navigation
| Command | Action |
|---|---|
h, j, k, l | Left, down, up, right |
w | Next word |
b | Previous word |
0 | Beginning of line |
$ | End of line |
gg | First line |
G | Last line |
:42 | Go to line 42 |
Ctrl-d / Ctrl-u | Scroll down/up |
Editing
| Command | Action |
|---|---|
i | Insert before cursor |
a | Insert after cursor |
I | Insert at line start |
A | Insert at line end |
o | Open line below |
O | Open line above |
x | Delete character |
dd | Delete line |
D | Delete to end of line |
cc | Change entire line |
J | Join line with next |
u | Undo |
Ctrl-r | Redo |
. | Repeat last command |
Copy, Cut, Paste
| Command | Action |
|---|---|
yy | Copy line |
yw | Copy word |
y$ | Copy to end of line |
dd | Cut line |
dw | Cut word |
p | Paste after |
P | Paste before |
Search
| Command | Action |
|---|---|
/pattern | Search forward |
?pattern | Search backward |
n | Next result |
N | Previous result |
* | Search word under cursor |
Replace
| Command | Action |
|---|---|
:s/old/new/ | Replace first in line |
:s/old/new/g | Replace all in line |
:%s/old/new/g | Replace all in file |
:%s/old/new/gc | Replace with confirmation |
Visual Mode (Selection)
| Command | Action |
|---|---|
v | Visual character mode |
V | Visual line mode |
y | Copy selection |
d | Delete selection |
Quick Reference Card
Most Common Workflow:
1. Open file: vim file.txt
2. Navigate: h,j,k,l or arrow keys
3. Start editing: i (insert) or a (append)
4. Type your text
5. Exit insert: ESC
6. Save and quit: :wq
Essential Shortcuts:
# Navigation
gg - Top of file
G - Bottom of file
0 - Start of line
$ - End of line
w / b - Next/previous word
# Editing
dd - Delete line
yy - Copy line
p - Paste
u - Undo
. - Repeat
# Search
/text - Find 'text'
n - Next result
# Save/Quit
:w - Save
:q - Quit
:wq - Save and quit
:q! - Quit without saving
Vim Configuration
Permanent Settings (.vimrc)
Create ~/.vimrc with basics:
| |
Runtime Settings
Apply these settings within vim for the current session:
| |
These are shortcuts for :set. Add them to .vimrc to make permanent (without the colon).
Tips for Daily Use
1. Learn the Movement Keys First
Before anything else, get comfortable with h, j, k, l and w, b. Your hands never leave home row.
2. Use . (Dot) Command
The dot command repeats your last change. Super powerful:
cw new<ESC> - Change word to "new"
w - Move to next word
. - Repeat the change
3. Shell Vi Mode Tricks
| |
4. Don’t Overthink It
Start with these basics. Add more as you need them. You don’t need to master everything at once.
Common Mistakes
Stuck in Insert Mode? Press ESC
Can’t Exit Vim? Type :q! and press Enter
Commands Not Working? Make sure you’re in normal mode (press ESC)
Slow Mode Switching? Add export KEYTIMEOUT=1 to your shell config
Resources
- Run
vimtutorin your terminal - 30 minute interactive tutorial - Vim Documentation
- OpenVim Tutorial - Interactive in browser
Practice Exercise
Try this workflow:
- Enable vi mode:
bindkey -v(zsh) orset -o vi(bash) - Type:
ls -la /usr/local/bin - Press
ESC - Press
0(go to start) - Press
wthree times (skip “ls -la”) - Press
cw(change word) - Type a new path
- Press
Enter
The key is practice. Use it daily and it becomes second nature.
Remember: You only need to know 20% of vim to be 80% effective. Start here, expand later.