The difference between: d [count] and d [count]

As a novice vim user, I used d[count]<Enter>to delete lines.
It seemed strange to me that the count + 1 lines were always deleted .
If I wanted to delete 2 lines, I typed d1, 3 lines took d2, ...

I finally found time trying to figure out why, and it seems like I should have used :d<count>.

This begs the question why, :d1<Enter><>d1<Enter>

+5
source share
2 answers

d<count>in normal mode does nothing, because at the expense of movement does not follow. So, presumably you click d<count><Enter>, and in this case, the movement associated with dis equal to <count><Enter>, which moves the lines <count>down. Since it <Enter>is a movement on Linux, it dwill also be linear, deleting all lines from the current to the line <count>down, inclusive.

The team you really wanted is <count>dd.

+11
source

d{motion}deletes text being moved {motion}. When you type 3<ENTER>, the cursor moves 3 lines below the current one, and therefore d3<ENTER>deletes this area.

:d[count]just deletes the lines [count].

The difference is that it {motion}does not match count.

, visual , , d.

+4

All Articles