I'm familiar with the "dd" and "d{motion}" commands, but can't find "dap" in vim's help.txt. What does "dap" do in normal mode and why? (Alternatively, how can I find out this sort of thing for myself?)
1 Answer
"dap" does not actually delete everything. For example, try putting this into your buffer:
1
1
2
2
3
3
Then put your cursor on either '2' and type "dap". It'll leave the '1's and '3's.
This is because "dap" deletes a paragraph. In fact, that's actually the mnemonic: "(D)elete (A) (P)aragraph". You can see it in the help under :h ap
:
*v_ap* *ap*
ap "a paragraph", select [count] paragraphs (see
|paragraph|).
Exception: a blank line (only containing white space)
is also a paragraph boundary.
When used in Visual mode it is made linewise.
This is called a "text object". You can read about these under: :h text-objects
, or you can read this awesome article on text objects.
Either way, the basic idea of text-objects is that you are defining the boundaries of an object and then apply commands to that whole object even when you're in the middle of it. For example, I'm sure you know you can use dw
to delete a word. But what if you're in this scenario?
Hello world
Cursor: ^
If you type dw
, you'll still have the wo
left. If you type diw
, that will delete inside of the word, so for the most part it's equivalent to typing bdw
.
How can I find out this sort of thing for myself?
You had the basic idea down! Checking the help is always a good start. In this case, you could have realized that d
is an operator, so the help you were really looking for was the argument to the operator, in this case ap
.
-
+1! To be pedantic: diw leaves the trailing space, while bdw does not. diw would be the same as bde ;-) The pendant for bdw is actually daw, which uses the same "a" as the stroke in the question. Jan 25, 2017 at 14:45
-
1@M.Herzkamp: And yet
diw
andbde
are still not quite the same: if your cursor's on the beginning of a word. Likewise, if your cursor is on a space between words, thenbdw
will delete the word on the left, whiledaw
will delete the word on the right. I think the original answer's "for the most part…" is probably the best that we'll get in terms of these equivalences.– wcharginJan 25, 2017 at 21:01