VI(1) BSD VI(1)
NAME
vi - screen-oriented (visual) display editor based on ex
SYNOPSIS
vi [ -t tag ] [ -r file ] [ +command ] [ -l ] [ -wn ] name ...
DESCRIPTION
vi (visual) is a display-oriented text editor based on an underlying line
editor ex(1). It is possible to use the command mode of ex from within
vi and vice-versa.
When using vi, changes you make to the file are reflected in what you see
on your terminal screen. The position of the cursor on the screen
indicates the position within the file.
The name argument indicates files to be edited.
OPTIONS
-t tag Edits the file containing the tag and positions the editor at
its definition.
-rfile Recovers file after an editor or system crash. If file is not
specified, a list of all saved files is printed.
+command The specified ex command is interpreted before editing begins.
-l Indent appropriately for LISP code, and modify (), {}, [[, and
]] commands to have meaning for LISP.
-wn Sets the default window size to n. This is useful when using
the editor over a slow-speed line.
VI MODES
Command Normal and initial mode. Other modes return to command mode
upon completion. ESC (escape) is used to cancel a partial
command.
Input Entered by the following options a i A I o O c C s S R.
Arbitrary text may then be entered. Input mode is normally
terminated with ESC character, or abnormally with interrupt.
Last line Reading input for : / ? or !; terminate with a carriage return
to execute, interrupt to cancel.
COMMAND SUMMARY
Sample commands
<- | | -> Arrow keys move the cursor
h j k l Same as arrow keys
itextESC Insert text abc
cwnewESC Change word to new
easESC Pluralize word
x Delete a character
dw Delete a word
dd Delete a line
3dd ... 3 lines
u Undo previous change
ZZ Exit vi, saving changes
:q!CR Quit, discarding changes
/textCR Search for text
CTRL/U CTRL/D Scroll up or down
:ex cmdCR Any ex or ed command
Counts before vi commands
Numbers may be typed as a prefix to some commands. They are interpreted
in one of these ways:
line/column number z G |
scroll amount CTRL/D CTRL/U
repeat effect Most of the rest
Interrupting, canceling
ESC End insert or incomplete cmd
DEL (Delete or rubout) interrupts
CTRL/L Reprint screen if DEL scrambles it
CTRL/R Reprint screen if CTRL/L is -> key
File manipulation
:wCR Write back changes
:qCR Quit
:q!CR Quit, discard changes
:e nameCR Edit file name
:e!CR Reedit, discard changes
:e +nameCR Edit, starting at end
:e +nCR Edit starting at line n
:e #CR Edit alternate file
Synonym for :e #
:w nameCR Write file name
:w! nameCR Overwrite file name
:shCR Run shell, then return
:!cmdCR Run cmd, then return
:nCR Edit next file in arglist
:n argsCR Specify new arglist
CTRL/G Show current file and line
:ta tagCR To tag file entry tag
CTRL/] :ta, following word is tag
In general, any ex or ed command (such as substitute or global) may be
typed, preceded by a colon and followed by a carriage return.
File Locking
:set al Enable file locking
:set noal Disable file locking
:set ba Enable automatic backup file creation
:set noba Disable automatic backup file creation
:set ro Enable readonly mode
:set noro Disable readonly mode
Positioning within file
CTRL/F Forward screen
CTRL/B Backward screen
CTRL/D Scroll down half screen
CTRL/U Scroll up half screen
G Go to specified line (end default)
/pat Next line matching pat
?pat Prev line matching pat
n Repeat last / or ?
N Reverse last / or ?
/pat/+n nth line after pat
?pat?-n nth line before pat
]] Next section/function
[[ Previous section/function
( Beginning of sentence
) End of sentence
{ Beginning of paragraph
} End of paragraph
% Find matching ( ) { or }
Adjusting the screen
CTRL/L Clear and redraw
CTRL/R Retype, eliminate @ lines
zCR Redraw, current at window top
z-CR ... at bottom
z.CR ... at center
/pat/z-CR pat line at bottom
zn.CR Use n line window
CTRL/E Scroll window down 1 line
CTRL/Y Scroll window up 1 line
Marking and returning
`` Move cursor to previous context
'' ... at first non-white in line
mx Mark current position with letter x
`x Move cursor to mark x
'x ... at first non-white in line
Line positioning
H Top line on screen
L Last line on screen
M Middle line on screen
+ Next line, at first non-white
- Previous line, at first non-white
CR Return, same as +
| or j Next line, same column
| or k Previous line, same column
Character positioning
^ First non white
0 Beginning of line
$ End of line
h or -> Forward
l or <- Backwards
CTRL/H Same as <-
space Same as ->
fx Find x forward
Fx f backward
tx Up to x forward
Tx Back upto x
; Repeat last f F t or T
, Inverse of ;
| To specified column
% Find matching ( { ) or }
Words, sentences, paragraphs
w Word forward
b Back word
e End of word
) To next sentence
} To next paragraph
( Back sentence
{ Back paragraph
W Blank delimited word
B Back W
E To end of W
Corrections during insert
CTRL/H Erase last character
CTRL/W Erase last word
erase Your erase, same as CTRL/H
kill Your kill, erase input this line
\ Quotes CTRL/H, your erase and kill
ESC Ends insertion, back to command
DEL Interrupt, terminates insert
CTRL/D Backtab over autoindent
|CTRL/D Kill autoindent, save for next
0CTRL/D ... but at margin next also
CTRL/V Quote non-printing character
Insert and replace
a Append after cursor
i Insert before cursor
A Append at end of line
I Insert before first non-blank
o Open line below
O Open above
rx Replace single char with x
RtextESC Replace characters
Operators
Operators are followed by a cursor motion, and affect all text that would
have been moved over. For example, since w moves over a word, dw deletes
the word that would be moved over. Double the operator, e.g., dd to
affect whole lines.
d Delete
c Change
y Yank lines to buffer
< Left shift
> Right shift
! Filter through command
= Indent for LISP
Miscellaneous Operations
C Change rest of line (c$)
D Delete rest of line (d$)
s Substitute chars (cl)
S Substitute lines (cc)
J Join lines
x Delete characters (dl)
X ... before cursor (dh)
Y Yank lines (yy)
Yank and Put
Put inserts the text most recently deleted or yanked. However, if a
buffer is named, the text in that buffer is put instead.
p Put back text after cursor
P Put before cursor
"xp Put from buffer x
"xy Yank to buffer x
"xd Delete into buffer x
Undo, Redo, Retrieve
u Undo last change
U Restore current line
. Repeat last change
"dp Retrieve d'th last delete
NOTES
In the Domain/OS BSD implementation of vi, the w (word) and CTRL/] (tag)
commands both recognize a $ as part of the word. The w command also
recognizes a dash (-) as part of a word, if LISP mode is on.
BUGS
Software tabs using CTRL/T work only immediately after the autoindent.
Left and right shifts on intelligent terminals do not make use of insert
and delete character operations in the terminal.
FILES
/usr/lib/ex?.?strings Error messages
/usr/lib/ex?.?recover Recover command
/usr/lib/ex?.?preserve Preserve command
/etc/termcap Terminal capability descriptions
~/.exrc Editor start-up file
/tmp/Exnnnnn Editor temporary
/tmp/Rxnnnnn Named buffer temporary
/usr/preserve Preservation directory
SEE ALSO
ex(1), edit(1), termcap (5), environ (7),
UNIX Text Processing.