Magnus
Magnus

Reputation: 11456

In Vim why is the behavior of "w" word selector inconsistent when preceded by "d" vs "v"

I'm wondering why in Vim the w key affects an inconsistent amount of text when preceded by d vs v. For example, suppose my cursor is over the "t" of "two" in this text:

one two three

Now dw produces:

one three

But vwd produces:

one hree

Is there some setting to make this more consistent, or do I need to write my own custom definition to fix it?

Also, the capital W selector is similarly inconsistent, and I'm wondering if there's a key for visually selecting the same portion that dW would have deleted? Best I can come up with is vfspace which is OK but wondered if there's anything shorter I'm missing that's built in.

Upvotes: 9

Views: 472

Answers (2)

jbr
jbr

Reputation: 6258

The w key does the same in both cases, it puts the cursor in the begining of the next word.

What is "inconsistent" is the v command.

In the first case dw means, delete up to, but not including, the cursor.

In the second case vwd deletes the selection, however the selection includes the cursor. You can clearly see this when you do vw.

Upvotes: 5

Kent
Kent

Reputation: 195209

yes there is one option: selection which default is inclusive. it makes v to select the last char.

:h 'selection' 

to check detail.

w is exclusive motion. but if in visual mode, it depends on the selection setting.

you could set selection to exclusive to make vwd and dw to behave identical.

Upvotes: 18

Related Questions