I know that to delete n lines, the command is [n]dd, where n is the number of lines to delete.
But what if I want to delete up to a certain line number? Say, if I'm on line 65 and I want to delete up to line 126 without having to do the math, how could I do that?
Deleting a single line in Vim editor: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.
The Vim goto line number command One can use the G letter. For example, press [ESC] key and type 10G (Shift-g) goto line number 10.
Step 1: Move your cursor to the top line of the block of text/code to remove. Step 2: Press V (Shift + v) to enter the Visual mode in Vim/Vi. Step 3: Now move your cursor down to the bottom of the block of text/code to remove. Step 4: Press d to delete the block selected.
d126G
Delete, line number, go.
A lot of commands in Vim can be followed by a move command to specify the scope.
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