5

The Vim Handbook gives them both the exact same description. From the Vim Handbook:

ap: "a paragraph", select [count] paragraphs. Exception: a blank line (only containing white space) is also a paragraph boundary. When used in Visual mode it is made linewise.

ip: "inner paragraph", select [count] paragraphs. Exception: a blank line (only containing white space) is also a paragraph boundary. When used in Visual mode it is made linewise.

Because of this, it is not entirely clear to me what the differences between these are. For example, say you had the commands gqap and gqip. How do they differ in behaviour?

Kalcifer
  • 1,211
  • 12
  • 18

1 Answers1

7

Again, just reading :help ap because someone gave you the link, without proper background, will get you nowhere and only bring more confusion.

Text objects can be of two types: those that include their boundaries and those that exclude their boundaries.

By convention, text objects that include their boundaries start with a, like ap, and those that exclude their boundaries start with i, like ip.

What constitutes a "paragraph" is explained under :help paragraph, which is linked from both :help ip and :help ap. In concrete terms, the boundaries of a paragraph are:

  • a non-empty line preceded by an empty one, think of it as zero-width match,
  • the next empty line.

So you have ip, which excludes the empty line, and ap, which includes it:

[...] end of paragraph above.

Beginning of paragraph in the middle    |       |
with some boring filler text so that    | ip    | ap
it covers a few lines.                  |       |
                                                |
Beginning of paragraph below [...]

When doing gq over a paragraph, using ip or ap doesn't really matter because the extra empty line is unlikely to change anything to what is being done to the text. ip and ap are a bit of an exception, here, because the difference between the two types of text objects usually matters quite a lot:

             it
    ----------------------
<h2>One day I will be a H1</h2>
-------------------------------
             at

See :help text-objects for a reference on the subject and :help 04.8 for a more gentle introduction.

As alluded to in my other answer, proper learning lets you develop an intuition that is hard to build from random, disconnected, links and tweets and so on.

romainl
  • 186,200
  • 21
  • 280
  • 313