Vi Reference

Submitted by: Submitted by

Views: 97

Words: 773

Pages: 4

Category: Science and Technology

Date Submitted: 05/11/2013 07:50 AM

Report This Essay

Vi Reference Card

Modes

Vi has two modes: insertion mode, and command mode. The editor begins in command mode, where cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key.

Yanking text

Like deletion, almost all yank commands are performed by typing y followed by a motion. For example y$ yanks to the end of line. Two other yank commands are: line line yy :y

Regular expressions

any single character except newline zero or more repeats any character in set any character not in set beginning, end of line beginning, end of word grouping contents of n th grouping . (dot) * [...] [^ ...] ^ , $ \< , \> \(. . . \) \n

Changing text

The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For example cw changes a word. A few other change commands are: to end of line line C cc p P

Counts

Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurance of the letter e. Even insertions may be repeated conveniently with this method, say to insert the same line 100 times.

Quitting

exit, saving changes quit (unless changes) quit (force, even if unsaved) :x :q :q!

Putting text

put after position or after line put before position or before line

Inserting text

insert before cursor, before line append after cursor, after line open new line after, line before replace one char, many chars i a o r , , , , I A O R

Ranges

Ranges may precede most “colon” commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3−7. Ranges are commonly combined with...