vimtricks.wiki Concise Vim tricks, one at a time.

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: W jumps over the entire https://example.com/path?q=1 in one keystroke
  • File paths: W treats /home/user/.config/vim/vimrc as a single unit
  • CLI flags: W jumps over --long-option=value at once
  • Faster movement through dense code with lots of punctuation

Tips

  • WORD motions work as operator targets: dW deletes to the start of the next WORD, cE changes to the end of the current WORD
  • iW and aW are the corresponding text objects: diW deletes the WORD under the cursor, daW includes surrounding whitespace
  • The iskeyword option controls what w/b/e consider part of a word, but W/B/E always use whitespace only
  • When in doubt, W is faster for coarse navigation; w is more precise for fine editing

Next

How do I run a search and replace only within a visually selected region?