Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "d1j" delete two lines in vim?

Tags:

command

vim

The d{motion} command seems to work inconsistently:

d1j  " deletes 2 lines to the bottom
d1l  " deletes 1 character to the right

Is it expected behaviour?

like image 443
Eugene Yarmash Avatar asked Apr 29 '11 13:04

Eugene Yarmash


People also ask

How do I delete alternate lines in vi?

Replace “<WORD>” with the word of the line you want to delete. For example, if you want to delete lines with the word “Linux”, then use the following approach: Press the “Esc” key to change mode. Type “:g /linux/d”, then hit “Enter”.

How do I delete multiple lines at a time in Vim?

Deleting Multiple Lines in Vi and VimInstead of simply pressing dd, you can specify the number of lines you want to delete. For example, typing 3dd will delete the next three lines from the file. You can also use wildcard characters in the aforementioned command.

What keyboard combination will delete an entire line in Vim?

Deleting a Line Press the Esc key to go to normal mode. Place the cursor on the line you want to delete. Type dd and hit Enter to remove the line.


1 Answers

When you start a motion and you are in operator pending mode, your motion will be either inclusive or exclusive, and either characterwise or linewise (linewise motions are always inclusive).

j is a linewise inclusive motion. Probably you want to try dvj or dgj (the latter one works with screen lines).

See :help operator. You can force motions to be linewise, characterwise or blockwise with V, v or CTRL-V respectively.

like image 158
Benoit Avatar answered Sep 24 '22 16:09

Benoit