Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete the remainder of the line after current word in VIM

Tags:

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.

like image 889
Sebastian Kramer Avatar asked Nov 06 '13 19:11

Sebastian Kramer


2 Answers

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
like image 179
Marco Baldelli Avatar answered Oct 16 '22 07:10

Marco Baldelli


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
like image 1
Zaffy Avatar answered Oct 16 '22 07:10

Zaffy