Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know I've probably looked over this a million times in all the VI documents I've read, but I can't seem to find the delete from cursor to end of line command.

share|improve this question
3  
You've got a typo here - you say "end of line" in the title, but "end of word" in the question. –  Jefromi Nov 30 '10 at 17:50

3 Answers 3

up vote 91 down vote accepted

The command dw will delete from the current cursor position to the beginning of the next word character. The command d$ will delete from the current cursor position to the end of the current line. D is a synonym for d$.

share|improve this answer
    
Yeah I know of dw, but I guess I just assumed there would be a "delete the rest of this line" command. For example my line has ip=|10.1.1.1 with | being the cursor location. Is there a command that will delete all the 10.1.1.1? –  Falmarri Nov 29 '10 at 21:03
1  
@Falmarri - I apologize, I must have misunderstood your question. There is a command for that: d$ –  Tok Nov 29 '10 at 21:04
27  
D (Shift+d) is also a synonym for d$. –  Neth Nov 29 '10 at 22:06

You probably want to use D. Move the cursor to the first character you want to delete, then hit shift-D. Everything gone. Actually, it's in the default cut buffer, so you can P or p paste it back in.

I use Dp (delete to end of line, then put it back), move to the end of some other line, then p again to paste the same text in at the end of this other line. Works wonders in config files, where you need to put some complicated URL in two or more places.

share|improve this answer
    
It's probably a minimal Vim he uses anyway. –  polemon Dec 3 '10 at 9:17

One of the nice things about vi is its logical command structure. d followed by a motion command deletes to the target of that motion. $ moves to the end of the line (mnemonic: like in regexps). So d$ deletes to the end of the line. Similarly, e moves to the end of the current word, and w moves to the beginning of the next word; so de deletes the end of the current word, and dw additionally deletes the following whitespace.

share|improve this answer
    
I'm used to emacs style so I was trying de which obviously wasn't working. I forgot about $ –  Falmarri Nov 29 '10 at 22:13
    
@gioele I use <kbd> for actual keys, not for command sequences. E.g. <kbd>Ctrl</kbd>+<kbd>C</kbd>, but d$. –  Gilles Apr 29 at 9:42

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.