Reputation: 21664
Is there a difference between :+d+CR and d+d in normal mode in vim?
It seems the former is an Ex command and they have the same effect.
Upvotes: 3
Views: 10337
Reputation: 76735
There are some commands that are only in visual mode, and some commands only in ex mode; but there are some commands in both. Deleting a line is in both.
In visual mode, you make up a command with three possible parts: a count, a command, and what the command should operate upon. The basic delete command is d
, and you can combine it with movement commands: move to next word is w
, delete to next word is dw
; move to next paragraph is }
, delete to next paragraph is d}
and so on. As a special shortcut, dd
deletes a line. You can delete three lines with 3dd
. But note that there are many, many ways to delete part of a line.
In ex mode, the delete command can only operate on whole lines. You can prefix the delete command with line numbers to delete a range of lines: :1,10d<Enter>
would delete lines 1 through 10. You can mark a line with mark b
and mark another line with mark e
and then delete from the one to the other like so: :'b,'ed<Enter>
And you can delete the current three lines by following d
with a count: :d3<Enter>
In ex mode, to operate within a line you need to use the s
command (substitute). To change hamburger to hot dog you would use: :s/hamburger/hot dog/<Enter>
In a sense, ex mode came first. The first editor was called ed
and ex
was a super-set of the features of ed
, and then added visual editing.
Upvotes: 7
Reputation: 1247
With :d
, you can add an integer after it to specify how many lines to delete. With dd
, you delete one line only.
For example, using :d3
will delete three lines; of course, if you just use :d
with no number following it, there is no difference.
EDIT: Thanks to steveha and BenjaminRH for clarifying below - it turns out you can delete using dd
by using a number before it. You can also repeat dd
by using a .
.
Upvotes: 5