Skip to content
Dev Discovers

word vs. WORD in Vim

vim2 min read

Vim has many motion commands like w, e, b and their uppercase counterparts that allow users to navigate text more quickly. When using these commands, it's important to understand the difference between "word" and "WORD".

:help 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, end-of-line). This can be changed with the 'iskeyword' option. An empty line is also considered to be a word.

In other words, a "word" is a sequence of characters that are separated by whitespace, punctuation, or the beginning/end of a line.

:help 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.

In other words, a "WORD" is a sequence of characters that are separated by whitespace or the beginning/end of a line. Punctuation is not considered a separator for a WORD.

Let's take a look at an example to illustrate the difference. Consider the following sentence:

The storm raged on all night: lightning flashed, thunder boomed, and the wind howled through the trees.

If we use the "w" command to navigate through the sentence, it would take us to each individual word:

The
storm
raged
on
all
night
:
lightning
flashed
,
thunder
boomed
,
and
the
wind
howled
through
the
trees
.

However, if we use the "W" command instead, it would take us to each individual WORD:

The
storm
raged
on
all
night:
lightning
flashed,
thunder
boomed,
and
the
wind
howled
through
the
trees.

Here's another comparison counting how many words / WORDs different text has:

TextwordsWORDs
This is a test44
list.size31
if (list.size > 3) {95

Additionally, it's important to use "word" and "WORD" appropriately in combination with other Vim commands. For example, if you want to delete a word or WORD, you can use the "dw" and "dW" commands, respectively.

© 2023 by Dev Discovers. All rights reserved.
Theme by LekoArts