Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My cursor is on the final character of a word in Vim. Without moving the cursor, is there any succinct way to delete the current word and the word before it?

As far as I can tell, the only way to delete the current word is to use diw. Using db leaves the character under the cursor (which happens to be the last character).

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I would do either 2dbx or vbbd. Or v5bd if there were 5 words to delete.

I prefer vbbd as I like to have some visual clue of what I'm going to do and it feels a bit cleaner.

share|improve this answer
    
Wow! I didn't realize that the final character would be highlighted in visual mode, considering it is not highlighted in normal mode. I had always assumed that operators had the same meaning in visual mode. –  wanttobegoodatvim Sep 12 '11 at 17:53
    
Yes, visual selection always includes the current character. I think it's more logical than d's behaviour to include the current character when going to the right and exclude it when going to the left. This behaviour is quite coherent with y and c's own behaviour but (IMHO) not really with the general idea of "the cursor is ON a letter". This "discrepancy" is another reason why I like to use visual selection. –  romainl Sep 12 '11 at 19:39
add comment

Backward moving actions, (like db) take effect from the boundary in front of the cursor.

Probably your easiest way to do this is something like xd2b - that takes care of the character under the cursor first.

Generally I prefer to use Bdw (or wdB) when deleting whole words, as this doesn't leave you with a double space where the word was. Obviously this depends on the context of your actions, and what else you're trying to achieve.

share|improve this answer
    
If you take care of the character under the word first, then the second to last character becomes the first, and it is left behind. d2bxx works (with the xs at the end), but it feels clunky. –  wanttobegoodatvim Sep 12 '11 at 17:00
    
I'm not sure what you mean. With the cursor on the last character of the word, as per the OP, x deletes the char, and leaves the cursor on the space/punctuation after the word. d2b then works fine. The only times this doesn't work, are if the word is the last one on the line, or the word is only a single character. Like I said in my answer - it depends on context. Also: I've edited the above as wde and edw are wrong (they delete the next word). –  paulw1128 Sep 14 '11 at 14:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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