user784637
user784637

Reputation: 16152

Difference between cutting lines with 10dd and d9 in vim?

If I understand correctly both commands cut 10 lines and allow you to paste them anywhere.

Are they both the same as (n-1)dd and dn+enter where n is the number of lines to be cut?

Upvotes: 2

Views: 281

Answers (1)

FDinoff
FDinoff

Reputation: 31439

The two relevant help section are copied below.

                                                        d
["x]d{motion}           Delete text that {motion} moves over [into register
                        x].  See below for exceptions.

                                                        dd
["x]dd                  Delete [count] lines [into register x] linewise.

10dd is the second one which deletes 10 lines from you current position.

d9 does nothing. d9j (or d9<CR>) is delete from the cursor to where the cursor ends up (which is9j) is nine lines below the current one. However the j or <CR> makes it linewise so the same thing is deleted.

Both of these commands delete 10 lines. so ndd is equivalent to d(n-1)j.

d9j might be easier to type than 10dd if you have set relativenumber turned on because the difference between the line you are on and the line you want to delete to are on the left hand side of your screen.

You can use d9k to delete 10 lines up from your cursor line which you can't do with dd. Or you can use dfa to delete upto and including the next a. d{motion} is more powerful than dd because it isn't restricted to only linewise deletions.

Which one you use is up to you but certain combinations are easier depending on where your cursor is.

Upvotes: 7

Related Questions