For a few
weeks months now I’m learnings how to use
VIM text-objects. There is
an extended help wth
help text-objects in VIM. I’m trying to condense the
VIM help in a smaller blog entry here.
What are a text-objects in vim? Text-objects are things like a
‘paragraph’ or the text between braces or something like a
word. Text-objects can be used with the normal vim commands
c. To make you really understand it, I can recommend using
to actually visually select your text object.
In vim’s text-objects documentation they talk about an important property. A text-object selection is either inner or not…
Some text-object selectors:
aw- a word, works on words
iw- inner word, works on words
ab- brace, works with text between ( and )
ib- inner brace, works with text between ( and )
...- there are many more
i is used to denote inner selection, the
Consider the following text:
(this is some stuff from Ubuntu’s bootchart implementation).
Now an inner brace selection will be
without the braces. An inner text-object selector will always select less than the normal block selection. The normal brace selection will select
with the braces. You can check this for your self with the
combo: control-V+a+b (normal selection) or control-V+i+b (inner
selection). Note the selection works from anywhere inside the
braces: it does not matter where the cursor is positioned.
dib you delete the inner brace text-object.
The word text-object works by letting you select only the word (= inner selection) or the word + whitespace (= normal selection). Thus, with the same sentence as above and the cursor positioned on the p of passed.
In contrast with, control-V+a+w, which selects
With the space after ‘passed’ also.
See vim’s online help for more info, but I hope this little text was helpful to you (It certainly helped me).