To select more than one row in the data view, click one row, then hold the Control (Windows) or Command (Mac) key and select each of the other rows you wish to edit or remove. To select a continuous list, click one row, then hold the Shift key and click the last row.
Make the vi/vim text editor show or hide line numbers Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.
I find this easier
https://superuser.com/questions/170795/how-can-i-select-and-delete-lines-of-text-in-vi
You can delete multiple(range) lines if you know the line numbers:
:[start_line_no],[end_line_no]d
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:
:45,101d
The lines between 45 and 101 including 45 and 101 will be deleted.
Sounds like you're entering the commands in command mode (aka. "Ex mode"). In that context :5d
would remove line number 5, nothing else. For 5dd
to work as intended -- that is, remove five consequent lines starting at the cursor -- enter it in normal mode and don't prefix the commands with :
.
Commands listed for use in normal mode (prefix with : for command mode).
Tested in Vim.
By line amount:
By line numbers:
Backwards range given, OK to swap (y/n)?
If you prefer a non-visual mode method and acknowledge the line numbers, I would like to suggest you an another straightforward way.
Example
I want to delete text from line 45 to line 101.
My method suggests you to type a below command in command-mode:
45Gd101G
It reads:
Go to line 45 (
45G
) then delete text (d
) from the current line to the line 101 (101G
).
Note that on vim
you might use gg
in stead of G
.
Compare to the @Bonnie Varghese's answer which is:
:45,101d[enter]
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:
+---------+----------+--------------------+
| syntax | <motion> | <operator><motion> |
+---------+----------+--------------------+
| command | 45G | d101G |
+---------+----------+--------------------+
d5d "cuts" five lines
I usually just throw the number in the middle like:
d7l = delete 7 letters
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With