vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by (and thus standardized by) the Single Unix Specification and POSIX.
In newer distros vi start vim (Vi IMproved).
vi is a modal editor: it operates in either insert mode (where typed text becomes part of the document) or normal mode (where keystrokes are interpreted as commands that control the edit session). For example, typing i while in normal mode switches the editor to insert mode, but typing i again at this point places an "i" character in the document. From insert mode, pressing the escape key switches the editor back to normal mode. A perceived advantage of vi's separation of text entry and command modes is that both text editing and command operations can be performed without requiring the removal of the user's hands from the home row. As non-modal editors usually have to reserve all keys with letters and symbols for the printing of characters, any special commands for actions other than adding text to the buffer must be assigned to keys which do not produce characters, such as function keys, or combinations of modifier keys such as Ctrl, and Alt with regular keys. Vi has the property that most ordinary keys are connected to some kind of command for positioning, altering text, searching and so forth, either singly or in key combinations. Many commands can be touch typed without the use of Shift, Ctrl or Alt. Other types of editors generally require the user to move their hands from the home row when touch typing:
For instance, replacing a word is cwreplacement textEsc which is a combination of two independent commands (change and word-motion) together with a transition into and out of insert mode. Text between the cursor position and the end of the word is overwritten by the replacement text. The operation can be repeated at some other location by typing ., the effect being that the word starting that location will be replaced with the same replacement text.
vi(m) [options] [file ..]
file .. A list of filenames. The first one will be the current file and read into the buffer. The cursor will be positioned on the first line of the buffer. You can get to the other files with the ":next" command. To edit a file that starts with a dash, precede the filelist with "--". - The file to edit is read from stdin. Commands are read from stderr, which should be a tty. -t {tag} The file to edit and the initial cursor position depends on a "tag", a sort of goto label. {tag} is looked up in the tags file, the associated file becomes the current file and the associated command is executed. Mostly this is used for C programs, in which case {tag} could be a function name. The effect is that the file containing that function becomes the current file and the cursor is positioned on the start of the function. See ":help tag-commands". -q [errorfile] Start in quickFix mode. The file [errorfile] is read and the first error is displayed. If [errorfile] is omitted, the filename is obtained from the "errorfile" option (defaults to "AztecC.Err" for the Amiga, "errors.err" on other systems). Further errors can be jumped to with the ":cn" command. See ":help quickfix".
Navigation | |
---|---|
j | Move down a line. |
k | Move up a line. |
l | Moves the cursor one space to the right. |
h | Moves the cursor one character to the left. |
w | Moves one word forward. |
b | Moves one word backwards. |
0 | Move to the start of the current line. |
$ | Move to the start of the current line. |
Ctrl+f | Moves forward one screen. |
Ctrl+b | Moves back one screen. |
Ctrl+d | Moves forward half a screen. |
Ctrl+v | Moves back half a screen. |
number G | Jumps to line number. |
G | Jumps to the last line in the file. |
gg | Jumps to the first line in the file. |
v | Select. |
/ | Find. |
Input modes | |
i | Text is added before the cursor. |
a | Text is added after the cursor. |
I | The text you type will be added to the start of the current line. |
A | Adds text to the end of the current line. |
o | Adds text to a new line below the current line. |
O | Adds text to a new line above the current line. |
cw | Replaces the current word with whatever you type. |
R | Replacing characters from the cursor's current position. |
C | Replaces characters in the current line until you stop typing. |
cc | Deletes the current line entirely and replaces it with what you type. |
r | If you want to change a single character, r makes the change without actually putting you into insert mode. |
Esc | Return from insert mode to command mode. |
Deleting and putting in buffer. | |
x | Delete a single character without leaving command mode. To delete a set number of characters starting with the cursor, use number of characters x. |
D | Removes the rest of the line to the right of the cursor. |
dw | Removes the end of the current word. |
dd | Removes the entire current line. |
u | Should you find that you have made a mistake, you can take advantage of Vim's undo feature by pressing u. Vim has a large Undo history, so if necessary, you can regress a long way. Of course, if you really have trouble, you might have to exit without saving any of your work. |
Copying | |
yy | Copy current line into buffer. |
Pasting | |
p | Paste text in buffer after cursor position. |
P | Paste text in buffer before cursor position. |
:help | Online help. |
---|---|
:q! | Quit without saving. |
:w [file] | Write to file [file]. |
:x | Save changes and quit. |