Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete from the current cursor position to a given line number in vi editor

Tags:

vi

editing

People also ask

Which command is used for deleting a line points by the cursor in vi editor?

Moving lines also requires two commands: dd (“delete”) and either p or P . To move one line, position the cursor anywhere on the line and type dd . For example, to delete 5 lines, type 5dd . Next, move the cursor to the line above where you want the deleted line reinserted and type p .

Which command deletes from current cursor position to the end of the line?

As others have mentioned: you can use d$ or D ( shift - d ) to delete from the cursor position until the end of the line.

How do I delete part of a line in Vim?

Deleting a single line in Vim editor: To delete a line, follow the steps below: 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”.


You could use something like d63G to delete from the current line until line 63.


To delete from a to b use

:a,bd

from current to b use

:,bd

(where a and b in code are replaced by your numbers)


Same as the accepted answer, but slightly faster to type:

d63gg deletes from the current line to line 63.


Why count lines? Go to the last line you want to delete and mark it by typing ma which "marks" it with identifier "a". Then go up to the top line that you want to delete and type d'a for delete to mark "a". Bam!