Vim tip 22: word and WORD motions
Definitions from :h word and :h WORD are quoted below to explain the difference between word and WORD.
word A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs,
<EOL>
). This can be changed with theiskeyword
option. An empty line is also considered to be a word.
WORD A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.
word based motions:
- w move to the start of the next word
- b move to the beginning of the current word if the cursor is not at the start of word. Otherwise, move to the beginning of the previous word
- e move to the end of the current word if cursor is not at the end of word. Otherwise, move to the end of next word
- ge move to the end of the previous word
- 3w move 3 words forward
- Similarly, a number can be prefixed for all the other commands discussed here
WORD based motions:
- W move to the start of the next WORD
192.1.168.43;hello
is considered as a single WORD, but has multiple words
- B move to the beginning of the current WORD if the cursor is not at the start of WORD. Otherwise, move to the beginning of the previous WORD
- E move to the end of the current WORD if cursor is not at the end of WORD. Otherwise, move to the end of next WORD
- gE move to the end of the previous WORD
All of these motions will work across lines. For example, if the cursor is on the last word of a line, pressing w will move to the start of the first word in the next line.
Video demo:
See also my Vim Reference Guide and curated list of resources for Vim.