Manual / vi
vi(1)
| VI(1) | General Commands Manual | VI(1) |
NAME
vi - screen oriented (visual) display editor based on ex
SYNOPSIS
vi [ file ]
DESCRIPTION
Vi (visual) is a display oriented text editor based on ex(1). Ex and vi run the same code; it is possible to get to the command mode of ex from within vi and vice-versa.
The Vi Quick Reference card and the Introduction to Display Editing with Vi describe the full Berkeley editor. What follows is the subset this vi implements. Changes affect the buffer, not the file, until it is written.
Modes. Start in command mode. i inserts text; Escape returns to command mode. :wq followed by Return writes and leaves; :q! discards the changes. ZZ writes if modified and quits.
Motion. h j k l move left, down, up and right. w b e move by words; W B E use whitespace-delimited words. 0 goes to column zero, ^ to the first nonblank, $ to the last character. G goes to the last line; 1G to the first; a count before G selects that line. f/F find the next/previous character on the line; t/T stop short of it; ; repeats the find and , reverses it. Most motions accept a leading decimal count.
Changes. i/a insert before/after the cursor; I/A at the first nonblank/end. o/O open a line below/above. d, c and y followed by a motion delete, change or yank its span; the motions include /pattern, ?pattern, n and N, which end the span at the match (the match itself is not included); dd, cc and yy operate on lines. x/X delete at/before the cursor; D/C act through end of line; Y yanks a line; s/S substitute characters/lines. p/P put the unnamed register after/before the cursor. A span that crosses lines is kept whole, characterwise, and is put back with its line breaks.
Registers. "a through "z before a yank, delete, change or put name a register: "ayy and "add store into register a, "ap and "aP put from it. The unnamed register then holds whatever was last used. Capital names ("A to "Z, append) and the numbered registers ("1 to "9) are not implemented, and neither is any other name; they, a register name followed by a command that is not a yank, delete, change or put, and a put from an empty register all ring the bell and change nothing. All the registers share one 3699-byte area; a yank that does not fit rings the bell and leaves that register empty, and so does a span of more than 250 lines. J joins lines, r replaces one character, and ~ changes case. u undoes the last change; another u redoes it.
Searching and ex commands. /pattern and ?pattern followed by Return search forward and backward; n repeats the search and N reverses it. The basic regular expressions are those of ed(1). A colon command is executed by the ex engine: :w, :wq, :q!, :e file, :1,$s/old/new/g and the rest.
Control-Z suspends the editor and restores the shell's terminal state; fg resumes it. The editor uses an alternate screen and restores the terminal on a normal exit; reset(1) recovers from an abnormal one.
Text is held in an EX.SWPxx swap file in the working directory, so a file may be larger than process memory, within the line-table limit below.
FILES
See ex(1).
/usr/man/VI this page
SEE ALSO
ex(1), ed(1), sh(1), reset(1), licenses(1), Vi Quick Reference'' card, An Introduction to Display Editing with Vi''.
AUTHOR
William Joy
Mark Horton added macros to visual mode and is maintaining version
3
DIAGNOSTICS
Exit status 0 on a clean session; nonzero when the shared ex engine recorded an editing or startup failure, even if the editor remained usable.
BUGS
At most 2048 lines, with bounded line lengths as described in ex(1). There is no gg, no full-screen replace mode R and no crash recovery. There is no normal-mode filter command: ! (!!, !}) is ignored; use the colon forms :%!cmd, :a,b!cmd and :r !cmd. :w !cmd shows its output for a moment and then repaints, without the hit-return pause POSIX requires after a command overwrites the screen; :!cmd does pause. A characterwise yank on one line holds 254 bytes. This is an implemented subset, not all of Berkeley vi.
| September 30, 2026 | maux |