- Mastering Vim
- Ruslan Osipov
- 263字
- 2021-06-10 18:51:32
Utilizing text objects
Text objects are an additional type of object in Vim. Text objects allow you to manipulate text within parentheses or quotes, which becomes really useful when working with code. Text objects are only available when combined with other operators like change or delete or a visual mode (see Visual and Select Modes in Chapter 3, Follow the Leader – Plugin Management).
Let's give it a shot. Navigate your cursor to the text between parentheses:
Now, type in di) (delete inside parentheses). This will delete the text inside parentheses:
This works similarly with a change command. Undo the previous change (u) and start in the same spot:
Execute c2aw (change the outside of two words) to delete two words (with the surrounding spaces) and enter insert mode:
Text objects come in two flavors—inner objects (prefixed by i) and outer objects (prefixed by a). Inner objects do not include white space (or other surrounding characters), while outer objects do.
A full list of text objects can be looked up through :help text-objects, but some interesting ones are as follows:
- w and W for words and WORDs
- s for sentences
- p for paragraphs
- t for HTML/XML tags
Pairs of characters that are most often used in programming are all supported as text objects: `, ', ", ), ], >, and } select the text enclosed by the characters.
One way to think about working with text objects is that it's like constructing sentences. Here are the two examples that we used previously broken down:

- 從零開始:數字圖像處理的編程基礎與應用
- JavaScript+DHTML語法與范例詳解詞典
- Visual Basic編程:從基礎到實踐(第2版)
- Mastering Spring MVC 4
- 數據結構簡明教程(第2版)微課版
- Access 2010數據庫基礎與應用項目式教程(第3版)
- Mastering LibGDX Game Development
- Mastering Python High Performance
- Python Data Analysis Cookbook
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- Application Development with Parse using iOS SDK
- 軟件設計模式(Java版)
- Go Systems Programming
- Android開發進階實戰:拓展與提升
- Build Your Own PaaS with Docker