How to delete line(s) below current line in vim?
The delete ex command will work nicely.
:+,$d
This will delete all the lines from current +1 till the end ($)
To delete the next 2 lines the follow range would work, +1,+2
or shorthand +,+2
:+,+2d
As @ib mentioned the :delete
or :d
command will move the cursor to the start of the line next to the deleted text. (Even with nostartofline
set). To overcome this we can issue the ``
normal mode command. ``
will jump back to the exact position before the last jump, in this case the :d
command. Our command is now
:+,+2denter``
Or as one ex command
:+,+2d|norm! ``
To make this easier we wrap this all up in a command:
command! -count=1 -register D :+,+<count>d <reg><bar>norm! ``
Now to delete the next following 3 lines:
:3D
This command can also take a {reg}
like :delete
and :yank
do. So deleting the next 4 lines into register a
would be:
:4D a
For more information
:h :d
:h :command
:h :command-register
:h :command-count
:h ``
dG should work.
This means delete all rows until end of file from current cursor.
This will delete ALL lines below the current one:
jdG
Unfortunately that will move the cursor to the beginning of current line after the deletion is made.