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?)

share|improve this question

"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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.