Syntax of vi Commands
In vi, editing commands have the following general form:
[n
]operator
[m
]motion
The basic editing operators are:
- c
Begin a change.
- d
Begin a deletion.
- y
Begin a yank (or copy).
If the current line is the object of the operation, the motion is the same as the operator: cc, dd, yy. Otherwise, the editing operators act on objects specified by cursor-movement commands or pattern-matching commands. (For example, cf. changes up to the next period.) n and m are the number of times the operation is performed, or the number of objects the operation is performed on. If both n and m are specified, the effect is n ×m.
An object of operation can be any of the following text blocks:
- word
Includes characters up to a whitespace character (space or tab) or punctuation mark. A capitalized object is a variant form that recognizes only whitespace.
- sentence
Is up to ., !, or ?, followed by two spaces.
- paragraph
Is up to the next blank line or paragraph macro defined by the para= option.
- section
Is up to the next nroff/troff section heading defined by the sect= option.
- motion
Is up to the character or other text object as specified by a motion specifier, including pattern searches.
Examples
- 2cw
Change the next two words.
- d}
Delete up to next paragraph.
- d^
Delete back to beginning of line.
- 5yy
Copy the next five lines.
- y]]
Copy up to the next section.
- cG
Change to the end of the edit buffer.
More commands and examples may be found in the section Changing and deleting text in Changing and deleting text.
Visual mode ...
Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.