Working Code
Create a practice file:
cat << 'EOF' > navigation.txt
Server configuration file.
host: localhost
port: 8080
database: postgres
timeout: 30
max_connections: 100
log_level: debug
EOF
vim navigation.txt
Vim opens in Normal mode. Instead of arrow keys, press h, j, k, l:
| Key | Direction | Mnemonic |
|---|---|---|
h | ← Left | Leftmost on the keyboard |
j | ↓ Down | j's hook points downward |
k | ↑ Up | k points upward |
l | → Right | Rightmost on the keyboard |
It feels odd at first, but your right hand never leaves the home row. You save the time it takes to reach for the arrow keys.
Try It Yourself
Word-by-word movement
Moving one character at a time is slow. Jump by words instead:
max_connections: 100
Try this on that line:
| Key | Action | Meaning |
|---|---|---|
w | Start of the next word | word |
b | Start of the previous word | back |
e | End of the current word | end |
Press w several times. The cursor hops max_connections → : → 100.
Line-level movement
host: localhost
| Key | Action |
|---|---|
0 | Start of the line (column 0) |
^ | First non-whitespace character on the line |
$ | End of the line |
Press 0 to jump to the beginning, $ to jump to the end.
File-level movement
What if the config file is 500 lines long? You can't press j 500 times:
| Key | Action |
|---|---|
gg | Top of the file |
G | Bottom of the file |
5G or :5 | Jump to line 5 |
Press G to go to the end of the file. Then press gg to snap back to the top!
Number prefixes
Type a number first and the next motion repeats that many times:
5j → move down 5 lines
3w → jump forward 3 words
10k → move up 10 lines
Try pressing 5j once. It's the same as pressing j five times.
"Why?" — Why hjkl instead of arrow keys?
When vi (Vim's ancestor) was born, keyboards didn't have arrow keys. So it used h, j, k, l — the keys already sitting on the home row.
Arrow keys exist today, but hjkl is still faster:
Arrow keys: move right hand → hit arrow → return to home row (~0.5 sec)
hjkl: hand stays put → move instantly (0 sec)
Multiply that by the thousands of cursor moves you make each day. Suffer through a few days and it becomes second nature.
Combining motion commands
Here's how it looks in a real code file:
# settings.py
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
DATABASE_URL = 'postgres://user:pass@localhost/mydb'
SECRET_KEY = 'abc123'
| What you want to do | Keys |
|---|---|
From DEBUG to SECRET_KEY | 3j |
To 'abc123' at the end of line | $ |
| Back to the comment on line 1 | gg |
| To line 3 | 3G or :3 |
| Scan by hopping through words | Repeat w |
Scrolling by screen
In long files, scrolling by screen is handy:
| Key | Action |
|---|---|
Ctrl+f | One screen down (forward) |
Ctrl+b | One screen up (backward) |
Ctrl+d | Half screen down (down) |
Ctrl+u | Half screen up (up) |
Use Ctrl+f to skim through a 500-line log file quickly.
Deep Dive
- Open the
navigation.txtyou just created withvim. - Jump to the top with
gg, then the bottom withG. - Jump to line 3 (
port: 8080) with3G. - Press
wto move word by word, thenbto step back. - Bounce between line start (
0) and line end ($). - Move down 5 lines with
5j, then up 3 lines with3k. - Navigate for 5 minutes using only
hjkl— no arrow keys allowed.
Quiz
Which key moves the cursor down by one line?
Which key jumps to the start of the next word?
Which key combination jumps to the top of the file?