Word Text Objects

The first text objects we will review are some of the simplest and most common, words. Neovim provides not one, but two definitions for words, and distinguishes between them using the notation "word" and "WORD".

word
A sequence of letters, digits, and underscores, separated by either non-word characters or whitespace.
WORD
A sequence of non-blank characters, separate by whitespace.

The differences between these two definitions can be clarified a bit with a simple example. Let's take a look at how each text object would treat the following text:

one two three-four five/six

The words in this sentence are what we would expect from basic English usage:

one, two, three, four, five, and six

The WORDs in this sentence, on the other hand, are slightly different:

one, two, three-four, and five/six

Let's look a bit more at what these examples. First, we can see that both text objects treat characters separated by whitespace the same. The difference is how they treat words that are separated by characters other than whitespace. In these cases the words text object takes a more conservative approach and considers anything other than "word-characters" to define word boundaries, while WORDs take a more liberal approach and consider most types of characters to be part of the word itself.

To further demonstrate these two text objects, let's start from the following buffer, and visually-select a word and a WORD:

Initial Condition
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
NORMAL
70%
7:5
 
Select word
viw
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:5
 
Select WORD
viW
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:5
 

In particular note that executing viw in Step 1 selected text up to, but not including, the apostrophe. On the other hand, executing viW in Step 2 selected the entire sequence of text, from the start of the line to the space. The ability to choose between either word and WORD provides additional flexibility to fine-tune which text is ultimately selected.

viw vs vaw

Let's now take a look at the difference between selecting inside and around word text objects. The example below show the sequence of selecting inside the word with viw, hitting Esc to return to normal mode, then selecting again using vaw.

Initial Conditions
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
NORMAL
70%
7:9
 
Visually select inside the word text object
viw
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:11
 
Return to Normal Mode
<Esc>
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
NORMAL
70%
7:11
 
Visually select around the word text object
vaw
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:12
 

The cursor starts in the middle of "known", then several things happened after executing viw. First, the selection extended from the first to the last character of the word. Second, the cursor moved to the last character of the word. As a result, after hitting Esc to return to normal mode the cursor remains in its new position. Next, in Step 2 we execute vaw to visually-select around the word, which behaves slightly differently than viw did previously. In particular, although the selection starts from the first character of the word, as it has done previously, it now extends until the character after the end of the word. In short, operating around the word text object includes the trailing whitespace.

Extending the Selection by word

Continuing from the previous example, we have still have an active selection around the word text object, as shown in the start condition below:

Initial Conditions
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:12
 
Extend the selection by one word
w
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:13
 
Extend the selection by another word
w
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:15
 
Extend the selection by another word
w
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:18
 

Now, suppose we want to extend the selection to include a few more words. We we can extend the selection to the start of the next word by hitting w again, as shown in Step 1, then repeated for several more words.

Extending the Selection by WORD

For comparison, let's cancel that selection then repeat that process, except this time we will use W to extend the selection so that we extend by WORD text objects.

Initial Conditions
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:12
 
Extend the selection by one word
W
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:13
 
Extend the selection by another word
W
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·he·said·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:18
 
Extend the selection by another word
W
that·it·has·come,·let·me·leave.·For·a·long·time,·I've·been·waiting·for
this·hour;·for·a·long·time,·I've·been·Vasudeva·the·ferryman.·Now·it's
enough.·Farewell,·but,·farewell,·river,·farewell,·Siddhartha!"
 
Siddhartha·made·a·deep·bow·before·him·who·bid·his·farewell.
 
"I've·known·it,"·hsaid·quietly.·"You'll·go·into·the·forests?"
 
"I'm·going·into·the·forests,·I'm·going·into·the·oneness,"·spoke
VISUAL
70%
7:21
 

Starting from the same position as the previous example, pressing W a single time in Step 1 has the same behavior as pressing w had; because the next word boundary is with whitespace the word and WORD text objects are the same. Hitting it again in Step 2, however, behaves somewhat differently. In this case, the WORD jumped past the punctuation to the start of the next word, then again in Step 3.

Having seen the basics of working with the simplest text objects, let's move on to learn about sentence text objects.