Syntax of vi Commands
In vi, commands have the following general form:
[n]operator[m]object
Here are the basic editing operators :
- 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 operator is the same as the object: cc, dd, yy. Otherwise, the editing operators act on objects specified by cursor-movement commands or pattern-matching commands. 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 can represent any of the following text blocks:
- Word
Includes characters up to a space or punctuation mark. A capitalized object is a variant form that recognizes only blank spaces.
- Sentence
Extends to
.,!, or?followed by two spaces.- Paragraph
Extends to next blank line or nroff/troff paragraph macro (defined by para
=option).- Section
Extends to next nroff/troff section heading (defined by sect
=option).
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 into temporary buffer (for future pasting)
- y]]
Copy up to the next section into temporary buffer (for future pasting)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access