How do I navigate by whitespace-separated WORDs instead of Vim's default word boundaries?
Answer
W / B / E
Explanation
Vim has two definitions of a "word": a lowercase word (letters, digits, underscores — or sequences of other non-blank characters) and an uppercase WORD (any non-blank characters). The uppercase motions W, B, and E jump by WORDs — they only stop at whitespace, ignoring punctuation, hyphens, dots, and other special characters.
word vs WORD
| Text | w stops |
W stops |
|---|---|---|
foo-bar |
foo, -, bar (3 words) |
foo-bar (1 WORD) |
src/main.py |
src, /, main, ., py (5 words) |
src/main.py (1 WORD) |
--flag=value |
--, flag, =, value (4 words) |
--flag=value (1 WORD) |
The motions
| Motion | Action |
|---|---|
W |
Forward to start of next WORD |
B |
Backward to start of previous WORD |
E |
Forward to end of current/next WORD |
gE |
Backward to end of previous WORD |
When to use WORD motions
- Navigating URLs:
Wjumps over the entirehttps://example.com/path?q=1in one keystroke - File paths:
Wtreats/home/user/.config/vim/vimrcas a single unit - CLI flags:
Wjumps over--long-option=valueat once - Faster movement through dense code with lots of punctuation
Tips
- WORD motions work as operator targets:
dWdeletes to the start of the next WORD,cEchanges to the end of the current WORD iWandaWare the corresponding text objects:diWdeletes the WORD under the cursor,daWincludes surrounding whitespace- The
iskeywordoption controls whatw/b/econsider part of a word, butW/B/Ealways use whitespace only - When in doubt,
Wis faster for coarse navigation;wis more precise for fine editing