Vim Text Objects
Select a word without surrounding white space
Suppose we want to select a word without surrounding white spaces, use the text object iw
for inner word using visual mode:
-
Got to normal mode by pressing
ESC
-
Type
viw
at the beginning of a word -
This will select the inner word
Select a word with surrounding white space
Suppose we want to select a word with a surrounding white space, use the text object aw
for around a word using visual mode:
-
Got to normal mode by pressing ESC
-
Type
vaw
at the beginning of a word -
This will select the word with white space
Select text inside a tag
We can select a text within an html
or xml
tag by using visual selection v
and text object it
.
- Go to normal mode py pressing
ESC
- Type
vit
from anywhere within thehtml
orxml
section - This will visually select all text inside the
tag
All other text objects can also be used to operate on the text inside the tag
cit
- delete text inside the tag and place ininsert
modedit
- delete text inside the tag and remain innormal
modecat
- delete around tag and place ininsert
modedat
- delete text around the tag and remain innormal
mode