Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

As a novice vim user, I used d[count]<Enter> to delete lines.
It striked me as odd that 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>

like image 571
Lieven Keersmaekers Avatar asked Feb 04 '11 08:02

Lieven Keersmaekers


People also ask

What's the difference between count and D_count?

COUNT function counts cells that contain only numbers, but COUNTA function counts cells that are not blank, including numbers. As Date and Time values are stored as serial numbers in Excel so these values are counted in both of these functions.

What is the difference between Count and Dcount in Zendesk?

COUNT: Counting all recorded values. DCOUNT: Counts only unique values.


2 Answers

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.

like image 190
hobbs Avatar answered Nov 02 '22 22:11

hobbs


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.

like image 29
eckes Avatar answered Nov 03 '22 00:11

eckes