- 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:

- Learning Scala Programming
- LabVIEW程序設(shè)計(jì)基礎(chǔ)與應(yīng)用
- SoapUI Cookbook
- SQL學(xué)習(xí)指南(第3版)
- Java EE框架整合開(kāi)發(fā)入門到實(shí)戰(zhàn):Spring+Spring MVC+MyBatis(微課版)
- JavaScript+jQuery網(wǎng)頁(yè)特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程(第2版)
- CentOS 7 Linux Server Cookbook(Second Edition)
- PostgreSQL技術(shù)內(nèi)幕:事務(wù)處理深度探索
- Scratch 3.0少兒編程與邏輯思維訓(xùn)練
- Apache Mahout Clustering Designs
- UVM實(shí)戰(zhàn)
- Deep Learning with R Cookbook
- Clojure for Finance
- 跟小樓老師學(xué)用Axure RP 9:玩轉(zhuǎn)產(chǎn)品原型設(shè)計(jì)
- Docker on Windows