Friday, November 30, 2007

Text Objects

Text objects are commands that can be used in combination with an operator or when in visual mode. Basically, you give a command followed by a description and Vim applies it to the relevant text object. Available commands include things like:

aw - a word
iw - inner word
aW - a word (leading and trailing whitespace included)
as - a sentence
etc...

In practice, these allow quick manipulation on the applied block of text. For example, you're in normal mode, and your cursor is positioned in the middle of a word. You type caw and Vim executes "change a word" deleting the existing word and switching to insert mode for you to perform your edit. For the full details on this feature see :help text-objects.

No comments: