0

If my cursor is between the words "because" and "and" in the following text, typing d2w in command mode deletes everything in between "because" and "su without".

because and su without

After typing d2w

becausesu without

  • Before typing d2w there was only one word between "because" and "su" so why were the white space characters either side of "and" also deleted?
  • Does d2w delete starting from the cursor or after the cursor?
  • Why is d2w deleting only one word and white space characters surrounding that word instead of deleting 2 words?
1

You should think of dw as delete until the next start of a word. Likewise d2w means delete until the second next start of a word. It is not the same as "delete a word."

because and su without
       ||   \__ 2w
       |\______ w
       \_______ cursor position

Before typing d2w there was only one word between "because" and "su" so why were the white space characters either side of "and" also deleted?

Do the motion 2w. Then imagine deleting up until that cursor position. The only thing that matters is that there are two starts of words (a̲nd and s̲u).

Does d2w delete starting from the cursor or after the cursor?

It deletes starting from the cursor, that is to say the cursor character is also deleted.

Why is d2w deleting only one word and white space characters surrounding that word instead of deleting 2 words?

Because it counts two starts of words forward then deletes everything until that point.

The operation daw and d2aw can be thought of as "delete a word" and "delete two words." This might be closer to what you were expecting.

  • The part "Because it counts two starts of words forward then deletes everything until that point." is what got me to understand how dw works. It's basically delete until start of a word, d2w is then delete until 2 starts of words. I didn't know about daw, it reads as "delete a word" which is easily remembered, thanks. Although may be you can clarify what is happening in the first diagram? – MyWrathAcademia Apr 24 at 15:48
  • a means "around" in this case (as in surroundings; not as in approximation). Compare ci( (change in parens) and ca( (change around parens). – DopeGhoti Apr 24 at 17:46
  • @DopeGhoti . You're right that daw actually means delete around word because I just found that sometimes daw deletes from a space before a word to the end of the word but other times daw deletes from the start of a word to a space at end of the word. Can you explain this behaviour? – MyWrathAcademia Apr 25 at 16:49
  • I'd have to experiment, but I suspect this has to do with cursor position. Is the behavior consistent if you daw with the cursor at the same position relative to the word? – DopeGhoti Apr 25 at 17:29
  • @DopeGhotti , as an example of daw's inconsistent behavior, the text "this is a word". When the cursor is on a character in the word "this" the result is "is a word". When the cursor is on a character in the word "is" the result is "this a word". When the cursor is on a character in the word "word" the result is "this a" – MyWrathAcademia Apr 25 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.