What is the difference between word and WORD motions in Vim?
Answer
w vs W, b vs B, e vs E
Explanation
Vim distinguishes between "words" (sequences of keyword characters) and "WORDS" (sequences of non-blank characters). The uppercase motions W, B, E move by WORDS, which are faster for skipping over punctuation-heavy text like paths, URLs, and code.
How it works
w— move to next word start (stops at punctuation boundaries)W— move to next WORD start (stops only at whitespace)b/B— move back by word/WORDe/E— move to end of word/WORD- A "word" is
[a-zA-Z0-9_]+, a "WORD" is[^ \t]+
Example
Text: file-name.txt /usr/local/bin http://example.com
Using w (word): file|-|name|.|txt| |/|usr|/|local|/|bin
Using W (WORD): file-name.txt| |/usr/local/bin| |http://example.com
Tips
Wis much faster for navigating code with dashes, dots, slashes, colonsdWdeletes an entire path or URL in one motioncWchanges a hyphenated-word without stopping at the hyphen- Use
wfor precise word-level editing,Wfor fast horizontal movement iWandaWare the text object versions:ciWchanges an entire WORD