I have tried to follow the following:
How to delete selected text in VI editor
but
5dd
gives
E492: Not an editor command: 5dd
I then tried:
5d
Which only deletes a single line. How can I delete multiple lines?
I have tried to follow the following:
How to delete selected text in VI editor
but
5dd
gives
E492: Not an editor command: 5dd
I then tried:
5d
Which only deletes a single line. How can I delete multiple lines?
If you prefer a non-visual mode method and acknowledge the line numbers, I would like to suggest you an another straightforward way.
Example
My method suggests you to type a below command in command-mode:
It reads:
Note that on
vim
you might usegg
in stead ofG
.Compare to the @Bonnie Varghese's answer which is:
The command above from his answer requires 9 times typing including enter, where my answer require 8 - 10 times typing. Thus, a speed of my method is comparable.
Personally, I myself prefer
45Gd101G
over:45,101d
because I like to stick to the syntax of the vi's command, in this case is:You can delete multiple(range) lines if you know the line numbers:
Note: d stands for delete
where,
start_line_no is the beginning line no you want to delete and end_line_no is the ending line no you want to delete. The lines between the start and end, including start and end will be deleted.
Eg:
The lines between 45 and 101 including 45 and 101 will be deleted.
Type
:set number
(for numbered lines).it is dxd, not ddx
if you want to delete 5 lines, cursor to the beginning of the first line to delete and d5d
Press the Esc key to make sure your are not in an edit mode. Place the cursor on the first line to be deleted. Enter
:5dd
. The current line, and the next four lines should be deleted.Alternately, if you have line numbering turned on...
Press the Esc key to make sure your are not in an edit mode. Enter
:#,#d
where '#' stands for the beginning and ending line numbers to be deleted.d5d "cuts" five lines
I usually just throw the number in the middle like:
d7l = delete 7 letters