The inner and outer word text objects in vim behave differently when combined with a count. Given the text (cursor is within the word first
)
first second third fourth
both y2iw
will put the first word in the register, y3iw
/y4iw
the first two word etc. So I need at least y7iw
to yank all four (inner) words. For outer words, the count given corresponds with the number of words yanked.
Why do two iw
objects correspond to a single word in this case, and can I get iw
to behave similar to aw
?
Best Answer
Type 5 or so spaces and do
viw
: the 5 or so spaces are seleced becauseiw
also considers\s+
as a separate "object".In your example, you have 7
iw
objects:yiw
yanksfirst
in the unnamed register.y2iw
yanksfirst
(with the trailing space) in the unnamed register.y3iw
yanksfirst second
(with the space) in the unnamed register.y4iw
yanksfirst second
(with the spaces) in the unnamed register.On the other hand,
aw
considers the word and any number of following space as an "object".In your example, you have 4
aw
objects:yaw
yanksfirst
(with the trailing space) in the unnamed register.y2aw
yanksfirst second
(with the trailing space) in the unnamed register.y3aw
yanksfirst second third
(with the trailing space) in the unnamed register.y4aw
yanksfirst second third fourth
in the unnamed register.If you want
iw
to behave likeaw
just useaw
.