开发者

Difference between :d[count] and d[count]

As a novice vim user, I used d[count]<Enter> to delete lines.

It striked me as odd tha开发者_开发百科t there were always count+1 lines deleted.

If I wanted to delete 2 lines, I typed 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜