Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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.

like image 240
Magnus Avatar asked May 29 '13 13:05

Magnus


People also ask

What Vim command would you use to remove the current line and place it into the default register?

The command to delete a line in Vim is dd . Below are step-by-step instructions to delete a line: Press the Esc key to go to normal mode. Place the cursor on the line you want to delete.


2 Answers

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.

like image 184
Kent Avatar answered Oct 10 '22 23:10

Kent


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.

like image 27
jbr Avatar answered Oct 10 '22 23:10

jbr