How can I select and delete lines of text in vi?

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

4 Answers

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

2

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 (or ZZ). A number can also be prefixed to dd to delete multiple lines, e.g. 3dd deletes 3 lines.

For more Vi commands, take a look at this handy Vi cheat sheet.

1

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

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}

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like