C.W.K.
Stream
Lesson 06 of 08 · published

Basic Movement

~14 min · vim, motion, navigation

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Why h j k l instead of arrow keys

Arrow keys live in the corner of the keyboard. Your right hand has to leave the home row, find them, navigate, and come back. h j k l are already under your right hand. The first day they feel awkward; by day three they feel like the arrow keys were a detour.

Vim was designed on the ADM-3A terminal in 1976, whose keyboard had those exact letters labeled with arrow icons. The convention stuck because it's mechanically excellent, not just for historical reasons.

Character movement

h, j, k, l for left, down, up, right. Yes, in that order — j goes down because it has a descender, k goes up because it has an ascender. The whole quest is full of these mnemonic accidents.

Word movement — the first big speed-up

Hopping character-by-character is fine for fine-grained edits, but most of the time you want to jump by words. w jumps to the start of the next word; e jumps to the end of the current (or next) word; b jumps backward to the start of the previous word.

Lowercase versions stop at punctuation: in hello-world they see three words. Uppercase versions (W E B) stop only at whitespace: in the same string they see one WORD. You'll use both constantly.

Line movement

0 jumps to the very start of the line; ^ jumps to the first non-blank character (usually what you actually want); $ jumps to the end. Imagine the keyboard row of numbers: 0 is the leftmost, $ sits over 4 on the right side — visual mnemonics again.

File-scale movement

gg jumps to the first line of the file; G jumps to the last line. :42 jumps to line 42 (so does 42G). Ctrl-d and Ctrl-u scroll half a page down/up; Ctrl-f and Ctrl-b scroll a full page.

Use a count. Almost every motion accepts a leading number: 5j moves five lines down, 3w jumps three words forward, 10l moves ten characters right. Combined with set relativenumber (Track 4), you can hop to an exact target by reading its number off the gutter.

Code

Character movement — h j k l·vim
h    " left
j    " down
k    " up
l    " right
Word movement·vim
w    " next word start
e    " next word end
b    " previous word start
ge   " previous word end
W    " next WORD start (whitespace-delimited)
E    " next WORD end
B    " previous WORD start
Line movement·vim
0    " first column
^    " first non-blank character
$    " end of line
g_   " last non-blank character
|    " first column (synonym for 0)
5|   " column 5
File and screen movement·vim
gg       " first line
G        " last line
:42      " go to line 42 (Command-line)
42G      " go to line 42 (Normal-mode shortcut)
H        " top line of screen ("High")
M        " middle line of screen ("Middle")
L        " bottom line of screen ("Low")
Ctrl-d   " half-page down
Ctrl-u   " half-page up
Ctrl-f   " full-page forward
Ctrl-b   " full-page back
zz       " center cursor on screen
zt       " cursor to top of screen
zb       " cursor to bottom

External links

Exercise

Open any source file 200+ lines long. Using only Normal-mode motions (no arrow keys, no mouse, no :), reach: (1) line 50, (2) the middle of the file, (3) the last word on the last line, (4) the closing brace that matches the first opening brace. Time yourself if you want a benchmark — sub-15-second is fluent.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.