So I can delete a text+line using dd (normal mode) and all the below text moves up a line.
I can go into visual mode using Ctrl+v
If I then say do 0
> C+v
> jjj
> $
> d
the text of 4 rows is deleted but the lines are not deleted.
How do I delete a block of text and delete the lines at the same time so any preceding lines of text move up to the cursor?
For something like this I usually use shift+v, jjj...d, but you could delete using text objects as well.
See :h text-object
. A few examples:
di"
- delete inside "
dap
- delete around paragraph
And you could of course use other commands than d
, such as c
or v
.
Something I use all the time is ci(
and ci"
for editing content inside ()
and ""
.
More cool examples using text-objects and visual mode can be found here:
What is your most productive shortcut with Vim?
You could use as well, i.e. 4dd
as mentioned by FDinoff, or a range, mentioned by Jens. However in most scenarios I personally believe using visual line (shift+v) is more flexible, and you don't have to count lines or anything. It's easy to remember, you see the result instantly, you won't miss counting lines and it'll work even if you're at the top/bottom on the screen.
Use either 4dd
to delete 4 lines of text.
Or
Use linewise visual block. <S-v>
then move to the last line you want to delete then press d
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