官术网_书友最值得收藏!

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

主站蜘蛛池模板: 佛学| 砀山县| 瑞安市| 侯马市| 灵山县| 本溪| 安阳市| 蒙山县| 澜沧| 金山区| 民权县| 凤翔县| 介休市| 民县| 兴宁市| 岑溪市| 正蓝旗| 资兴市| 都兰县| 洛隆县| 改则县| 潼南县| 万盛区| 山阳县| 彭阳县| 湘潭市| 屏南县| 城市| 襄汾县| 华蓥市| 东乌珠穆沁旗| 滕州市| 兴和县| 平顶山市| 铁力市| 遵义县| 根河市| 桑植县| 樟树市| 延安市| 桐庐县|