Sebastian Kramer
Sebastian Kramer

Reputation: 719

Delete the remainder of the line after current word in VIM

I would like to delete the text following the word the cursor is currently over at. E.g.

The quick brown fox jumps over the lazy dog
     ^ the cursor is here
The quick 
        ^ the desired result

eD is quite close to what I would like to accomplish but it removes the character the cursor is over at too. <C-U> does the exact job but from the cursor to the beginning of the line. Is there any combination which does the same forward?

Is there any other way to accomplish this than by creating another key mapping? There are quite a few shortcuts in vim so avoiding creating another one would be great.

Upvotes: 6

Views: 431

Answers (2)

Marco Baldelli
Marco Baldelli

Reputation: 3728

If you are in NORMAL mode, here are a couple of solutions.

First solution:

wDD

Explanation:

  1. Move one word forward
  2. Delete the characters under the cursor until the end of the line
  3. Delete the characters under the cursor until the end of the line

Second solution:

f<space>D

Explanation:

  1. Move to first occurrence of <space> to the right
  2. Delete the characters under the cursor until the end of the line

Upvotes: 6

user823738
user823738

Reputation: 17521

What about:

  1. jump after word with w
  2. then delete the rest of line with d$
  3. remove skipped space after the word with x

So:

wd$x

Upvotes: 1

Related Questions