Difference between :d[count] and d[count]
As a novice vim user, I used d[count]<Enter>
to delete lines.
d1
, 3 lines took d2
, ...
I finally took the time trying to understand why and it appears I should have been using :d<count>
.
That does beg for the question though, why is :d1<Enter>
<> d1<Enter>
d<count>
in normal mode doesn't do anything, because the count isn't followed by a motion. So presumably you've been hitting d<count><Enter>
, in which case the motion associated with d
is <count><Enter>
, which moves <count>
lines downward. Since <Enter>
is a linewise motion, the d
will also be linewise, deleting all lines from the current one to the line <count>
downward, inclusive.
The command you actually wanted is <count>dd
.
d{motion}
deletes the text that {motion}
moves over. When you type 3<ENTER>
, the cursor moves 3 lines below the current and therefore d3<ENTER>
deletes that area.
:d[count]
simply deletes [count]
lines.
The difference is that {motion}
is not the same as count
.
To get around that, you could use the visual
mode and select what you're going to delete and then simply press d
.
精彩评论