If I want to select particular text of line and delete lines, how can I do that in vi (give the simplest means)?

link|improve this question
feedback

migrated from stackoverflow.com Aug 2 '10 at 8:56

This question came from our site for professional and enthusiast programmers.

4 Answers

You can also use "V" in view mode to launch "VISUAL" mode. Select your lines and type "d" to delete them.

link|improve this answer
That is, Shift + V. – Josh Aug 2 '10 at 12:40
feedback

Move to the line you want to delete, either using the arrow keys or the j/k keys, and type dd. You can then save and exit by typing :x. For more Vi commands, take a look at this handy Vi cheat sheet.

link|improve this answer
1  
dd is the quickest way to delete a line. – Shivan Raptor Aug 2 '10 at 11:57
feedback

go to the first line you wish to delete, and type (in view mode) d[x-1] to delete x lines.

link|improve this answer
feedback

Another tip: if you want to delete a text paragraph, move to beginning of that paragraph with { and then type d}

Or, in other words, {d}

link|improve this answer
2  
Or dap, delete a paragraph – grawity Aug 2 '10 at 9:54
Thanks! I learn here something new every day. :-) – Janne Pikkarainen Aug 2 '10 at 10:01
@grawity: dap doesn't work for me in Vi. – Josh Aug 2 '10 at 11:19
@Josh: 97% of the time, when someone says "vi", he either means "vim" or "vim running in vi-compatibility mode". So I suggested a vim-specific command (see also :help text-objects). – grawity Aug 2 '10 at 20:20
@grawity: Sorry, I am running Vim, but dap still has no effect. – Josh Aug 2 '10 at 20:52
feedback

Your Answer

 
or
required, but never shown