Tri
Tri

Reputation: 113

Why does 'a' represents outer in vim not 'o'?

In vim, when you want to delete an inner word, you can press the following in the normal mode:

diw

but if you want to delete an outer word, you should press:

daw

now the question is, i represents inner, but why in the outer situation, it is not dow but daw?

Upvotes: 1

Views: 203

Answers (1)

romainl
romainl

Reputation: 196777

From :help text-objects:

The commands that start with "a" select "a"n object including white space, the commands starting with "i" select an "inner" object without white space, or just the white space. Thus the "inner" commands always select less text than the "a" commands.

Note that the boundaries of a text object are an integral part of the text object. If "inner" is what is inside those boundaries, then "outer" would be what is outside of them, thus everything else in the buffer.

From that point of view, selecting what is inside the boundaries and the boundaries themselves is really selecting "a" whole text objet.

Foo <span>bar</span> baz.
                           -- actual meaning --
    <---->   <----->       the boundaries of the text object
          <->              what is inside those boundaries
                             -> "inner text object"
                             -> "it"
    <-------------->       the boundaries + what is inside them
                             -> "a text object"
                             -> "at"

                           -- hypothetical meaning --
<-->                <--->  what is outside of the boundaries
                             -> "outer text object"
                             -> "ot"

Upvotes: 6

Related Questions