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
viwat 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
vawat 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
vitfrom anywhere within thehtmlorxmlsection - 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 ininsertmodedit- delete text inside the tag and remain innormalmodecat- delete around tag and place ininsertmodedat- delete text around the tag and remain innormalmode
