docs: Recover 10.exref 11.vitut 12.vi 13.viref USD papers
[dragonfly.git] / share / doc / usd / 12.vi / viapwh / vi.apwh.ms
1 .\" Copyright (c) 1980, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)vi.apwh.ms  8.2 (Berkeley) 8/18/96
29 .\"
30 .nr LL 6.5i
31 .nr FL 6.5i
32 .TL
33 Vi Command & Function Reference
34 .AU CB 2675
35 Alan P.W. Hewett
36 .sp
37 Revised for version 2.12 by Mark Horton
38 .CB
39 .NH 1
40 Author's Disclaimer
41 .LP
42 This document does not claim to be 100% complete.  There are a
43 few commands listed in the original document that I was unable
44 to test either because I do not speak \fBlisp\fR, because they
45 required programs we don't have, or because I wasn't able to make
46 them work.  In these cases I left the command out.  The commands
47 listed in this document have been tried and are known to work.
48 It is expected that prospective users of this document will read
49 it once to get the flavor of everything that \fBvi\fR can do
50 and then use it as a reference document.  Experimentation is
51 recommended.  If you don't understand a command, try it and
52 see what happens.
53 .LP
54 [Note: In revising this document, I have attempted to make it
55 completely reflect version 2.12 of
56 .B vi .
57 It does not attempt to document the VAX version (version 3),
58 but with one or two exceptions (wrapmargin, arrow keys)
59 everything said about 2.12 should apply to 3.1.
60 .I "Mark Horton" ]
61 .NH 1
62 Notation
63 .LP
64 \fB[option]\fR is used to denote optional parts of a command.
65 Many \fBvi\fR commands have an optional count.  \fB[cnt]\fR
66 means that an optional number may precede the command to
67 multiply or iterate the command.
68 \fB{variable item}\fR is used to denote parts of the command
69 which must appear, but can take a number of different values.
70 \fB<character [-character]>\fR means that the character or
71 one of the characters in the range described between the
72 two angle brackets is to be typed.
73 For example \fB<esc>\fR means
74 the \fBescape\fR key is to be typed.  \fB<a-z>\fR means that a
75 lower case letter is to be typed.  \fB^<character>\fR means that
76 the character is to be typed as a \fBcontrol\fR character, that is,
77 with the \fB<cntl>\fR key held down while simultaneously typing
78 the specified character.  In this document control characters will
79 be denoted using the \fIupper case\fR character, but
80 ^<uppercase chr> and ^<lowercase chr> are equivalent.  That is, for
81 example, \fB<^D>\fR is equal to \fB<^d>\fR.
82 The most common character abbreviations
83 used in this list are as follows:
84 .VL 8
85 .IP <esc> 8
86 escape, octal 033
87 .IP <cr> 8
88 carriage return, ^M, octal 015
89 .IP <lf> 8
90 linefeed ^J, octal 012
91 .IP <nl> 8
92 newline, ^J, octal 012 (same as linefeed)
93 .IP <bs> 8
94 backspace, ^H, octal 010
95 .IP <tab> 8
96 tab, ^I, octal 011
97 .IP <bell> 8
98 bell, ^G, octal 07
99 .IP <ff> 8
100 formfeed, ^L, octal 014
101 .IP <sp> 8
102 space, octal 040
103 .IP <del> 8
104 delete, octal 0177
105 .LE
106 .sp 1
107 .NH 1
108 Basics
109 .LP
110 To run \fBvi\fR the shell variable \fBTERM\fR must be defined and
111 exported to your environment.
112 How you do this depends on which shell you are using.
113 You can tell which shell you have by the character it
114 prompts you for commands with.
115 The Bourne shell prompts with `$', and the C shell prompts with `%'.
116 For these examples, we will suppose
117 that you are using an HP 2621 terminal, whose termcap name is ``2621''.
118 .NH 2
119 Bourne Shell
120 .LP
121 To manually set your terminal type to 2621 you would type:
122 .DS
123 TERM=2621
124 export TERM
125 .DE
126 .PP
127 There are various ways of having this automatically or
128 semi-automatically done when you log in.
129 Suppose you usually dial in on a 2621.
130 You want to tell this to the machine, but still have it
131 work when you use a hardwired terminal.
132 The recommended way, if you have the
133 .B tset
134 program, is to use the sequence
135 .DS
136 tset \-s \-d 2621 > tset$$
137 \&. tset$$
138 rm tset$$
139 .DE
140 in your .login (for csh) or the same thing using `.' instead of `source'
141 in your .profile (for sh).
142 The above line says that if you are dialing in you are on a 2621,
143 but if you are on a hardwired terminal it figures out your terminal
144 type from an on-line list.
145 .NH 2
146 The C Shell
147 .LP
148 To manually set your terminal type to 2621 you would type:
149 .DS
150 setenv TERM 2621
151 .DE
152 .PP
153 There are various ways of having this automatically or
154 semi-automatically done when you log in.
155 Suppose you usually dial in on a 2621.
156 You want to tell this to the machine, but still have it
157 work when you use a hardwired terminal.
158 The recommended way, if you have the
159 .B tset
160 program, is to use the sequence
161 .DS
162 tset \-s \-d 2621 > tset$$
163 source tset$$
164 rm tset$$
165 .DE
166 in your .login.*
167 .FS
168 * On a version 6 system
169 without environments, the invocation of tset
170 is simpler, just add the line ``tset \-d 2621''
171 to your .login or .profile.
172 .FE
173 The above line says that if you are dialing in you are on a 2621,
174 but if you are on a hardwired terminal it figures out your terminal
175 type from an on-line list.
176 .NH 1
177 Normal Commands
178 .LP
179 \fBVi\fR is a visual editor with a window on the file.  What
180 you see on the screen is \fBvi\fR's current notion of
181 what your file will contain,
182 (at this point in the file),
183 when it is written out.
184 Most commands do not cause any change in the screen until the
185 complete command is typed.  Should you get confused while
186 typing a command, you can abort the command by typing an
187 <del> character.  You will know you are back to command level
188 when you hear a <bell>.  Usually typing an <esc> will produce the
189 same result.  When \fBvi\fR gets an improperly formatted command
190 it rings the <bell>.
191 Following are the \fBvi\fR commands broken down by function.
192 .NH 2
193 Entry and Exit
194 .LP
195 To enter
196 .B vi
197 on a particular
198 .I file ,
199 type
200 .DS
201 \fBvi\fP \fIfile\fP
202 .DE
203 The file will be read in and the cursor will be placed at the beginning
204 of the first line.
205 The first screenfull of the file will be displayed on the terminal.
206 .PP
207 To get out of the editor, type
208 .DS
209 ZZ
210 .DE
211 If you are in some special mode, such as input mode
212 or the middle of a multi-keystroke command, it may
213 be necessary to type <esc> first.
214 .NH 2
215 Cursor and Page Motion
216 .LP
217 .VL 16
218 .B NOTE:
219 The arrow keys (see the next four commands)
220 on certain kinds of terminals will not work with the
221 PDP-11 version of vi.  The control versions or the hjkl versions will
222 work on any terminal.  Experienced users prefer the hjkl keys because
223 they are always right under their fingers.  Beginners often prefer
224 the arrow keys, since they do not require memorization of which hjkl
225 key is which.
226 The mnemonic value of hjkl is clear from looking at the keyboard of an adm3a.
227 .sp
228 .IP "[cnt]<bs> or [cnt]h or [cnt]\(<-" 16
229 .br
230 Move the cursor to the left one character.  Cursor stops at the left
231 margin of the page.
232 If cnt is given, these commands move that many spaces.
233 .IP "[cnt]^N or [cnt]j or [cnt]\(da or [cnt]<lf>" 16
234 .br
235 Move down one line.
236 Moving off the screen scrolls the window to force a new line
237 onto the screen.
238 Mnemonic: \fBN\fRext
239 .IP "[cnt]^P or [cnt]k or [cnt]\(ua" 16
240 .br
241 Move up one line.
242 Moving off the top of the screen forces new text onto the screen.
243 Mnemonic: \fBP\fRrevious
244 .IP "[cnt]<sp> or [cnt]l or [cnt]\(->" 16
245 .br
246 Move to the right one character.
247 Cursor will not go beyond the end of the line.
248 .IP [cnt]- 16
249 Move the cursor up the screen to the beginning of the next line.
250 Scroll if necessary.
251 .IP "[cnt]+ or [cnt]<cr>" 16
252 .sp 1
253 Move the cursor down the screen to the beginning of the next line.
254 Scroll up if necessary.
255 .IP "[cnt]$" 16
256 Move the cursor to the end of the line.
257 If there is a count, move to the end of the line "cnt" lines
258 forward in the file.
259 .IP "^" 16
260 Move the cursor to the beginning of the first word on the line.
261 .IP "0" 16
262 Move the cursor to the left margin of the current line.
263 .IP "[cnt]|" 16
264 Move the cursor to the column specified by the count.  The default is
265 column zero.
266 .IP "[cnt]w" 16
267 Move the cursor to the beginning of the next word. If there
268 is a count, then move forward that many words and
269 position the cursor at the beginning of the word.
270 Mnemonic: next-\fBw\fRord
271 .IP "[cnt]W" 16
272 Move the cursor to the beginning of the next word which follows
273 a "white space" (<sp>,<tab>, or <nl>).  Ignore other punctuation.
274 .IP "[cnt]b" 16
275 Move the cursor to the preceding word.  Mnemonic: \fBb\fRackup-word
276 .IP "[cnt]B" 16
277 Move the cursor to the preceding word that is separated from the
278 current word by a "white space" (<sp>,<tab>, or <nl>).
279 .IP "[cnt]e" 16
280 Move the cursor to the end of the current word or the end of the
281 "cnt"'th word hence.  Mnemonic: \fBe\fRnd-of-word
282 .IP "[cnt]E" 16
283 Move the cursor to the end of the current word which is delimited by
284 "white space" (<sp>,<tab>, or <nl>).
285 .IP "[line number]G" 16
286 .br
287 Move the cursor to the line specified.  Of particular use are the
288 sequences "1G" and "G", which move the cursor to the beginning and
289 the end of the file respectively.  Mnemonic: \fBG\fRo-to
290 .LP
291 .B NOTE:
292 The next four commands (^D, ^U, ^F, ^B)
293 are not true motion commands, in that they
294 cannot be used as the object of commands such as delete or change.
295 .IP "[cnt]^D" 16
296 Move the cursor down in the file by "cnt" lines (or the last "cnt"
297 if a new count isn't given.  The initial default is half a page.)  The
298 screen is simultaneously scrolled up.  Mnemonic: \fBD\fRown
299 .IP "[cnt]^U" 16
300 Move the cursor up in the file by "cnt" lines.  The screen is simultaneously
301 scrolled down.  Mnemonic: \fBU\fRp
302 .IP "[cnt]^F" 16
303 Move the cursor to the next page.  A count moves that many pages.
304 Two lines of the previous page are kept on the screen for continuity if
305 possible.  Mnemonic: \fBF\fRorward-a-page
306 .IP "[cnt]^B" 16
307 Move the cursor to the previous page.  Two lines of the current page
308 are kept if possible.  Mnemonic: \fBB\fRackup-a-page
309 .IP "[cnt](" 16
310 Move the cursor to the beginning of the next sentence.
311 A sentence is defined as ending with a ".", "!", or "?"
312 followed by two spaces or a <nl>.
313 .IP "[cnt])" 16
314 Move the cursor backwards to the beginning of a sentence.
315 .IP "[cnt]}" 16
316 Move the cursor to the beginning of the next paragraph.  This command
317 works best inside \fBnroff\fR documents.  It understands two sets of
318 \fBnroff\fR macros, \fB\-ms\fR and \fB\-mm\fR, for which the
319 commands ".IP", ".LP", ".PP", ".QP", "P", as well as the nroff command ".bp"
320 are considered to be paragraph delimiters.
321 A blank line also delimits a paragraph.
322 The \fBnroff\fR macros that it accepts as paragraph delimiters is
323 adjustable.  See \fBparagraphs\fR under the \fBSet Commands\fR section.
324 .IP "[cnt]{" 16
325 Move the cursor backwards to the beginning of a paragraph.
326 .IP "]]" 16
327 Move the cursor to the next "section", where a section is defined by
328 two sets of \fBnroff\fR macros, \fB\-ms\fR and \fB\-mm\fR, in which
329 ".NH", ".SH", and ".H" delimit a section.  A line beginning with a <ff><nl>
330 sequence, or a line beginning with a "{" are also considered to
331 be section delimiters.  The last option makes it
332 useful for finding the beginnings of C functions.
333 The \fBnroff\fR macros that are used for section delimiters can be adjusted.
334 See \fBsections\fR under the \fBSet Commands\fR section.
335 .IP "[[" 16
336 Move the cursor backwards to the beginning of a section.
337 .IP "%" 16
338 Move the cursor to the matching parenthesis
339 or brace.  This is very useful in C or lisp code.  If the
340 cursor is sitting on a \fB( ) {\fR or \fB}\fR the cursor
341 is moved to the matching character at the other end of the
342 section.  If the cursor is not sitting on a brace or a
343 parenthesis, \fBvi\fR searches forward until it finds one
344 and then jumps to the match mate.
345 .IP "[cnt]H" 16
346 If there is no count move the cursor to the top left position on the screen.
347 If there is a count, then move the cursor to the beginning of the line
348 "cnt" lines from the top of the screen.  Mnemonic:  \fBH\fRome
349 .IP "[cnt]L" 16
350 If there is no count move the cursor to the beginning
351 of the last line on the screen.
352 If there is a count, then move the cursor to the beginning of the line
353 "cnt" lines from the bottom of the screen.  Mnemonic: \fBL\fRast
354 .IP "M" 16
355 Move the cursor to the beginning of the middle line on the screen.
356 Mnemonic: \fBM\fRiddle
357 .IP "m<a-z>" 16
358 This command does not move the cursor, but it \fBmarks\fR the place
359 in the file and the character "<a-z>" becomes the label for referring
360 to this location in the file.  See the next two commands.  Mnemonic:
361 \fBm\fRark
362 .B NOTE:
363 The mark command is not a motion, and cannot be used as the target
364 of commands such as delete.
365 .IP "\(aa<a-z>" 16
366 Move the cursor to the beginning of the line that is marked with the label
367 "<a-z>".
368 .IP "\(ga<a-z>" 16
369 Move the cursor to the exact position on the line that was marked with
370 with the label "<a-z>".
371 .IP "\(aa\(aa" 16
372 Move the cursor back to the beginning of the line where it was before the
373 last "non-relative" move.  A "non-relative" move is something such as a
374 search or a jump to a specific line in the file, rather than moving the
375 cursor or scrolling the screen.
376 .IP "\(ga\(ga" 16
377 Move the cursor back to the exact spot on the line where it was located
378 before the last "non-relative" move.
379 .LE
380 .NH 2
381 Searches
382 .LP
383 The following commands allow you to search for items in a file.
384 .VL 16
385 .IP [cnt]f{chr} 16
386 .sp 1
387 Search forward on the line for the next or "cnt"'th occurrence of
388 the character "chr".  The cursor is placed \fBat\fR the character
389 of interest.  Mnemonic: \fBf\fRind character
390 .IP [cnt]F{chr} 16
391 .sp 1
392 Search backwards on the line for the next or "cnt"'th occurrence of
393 the character "chr".  The cursor is placed \fBat\fR the character
394 of interest.
395 .IP [cnt]t{chr} 16
396 .sp 1
397 Search forward on the line for the next or "cnt"'th occurrence of
398 the character "chr".  The cursor is placed \fBjust preceding\fR
399 the character of interest.  Mnemonic: move cursor up \fBt\fRo character
400 .IP [cnt]T{chr} 16
401 .sp 1
402 Search backwards on the line for the next or "cnt"'th occurrence of
403 the character "chr".  The cursor is placed \fBjust preceding\fR
404 the character of interest.
405 .IP "[cnt];" 16
406 Repeat the last "f", "F", "t" or "T" command.
407 .IP "[cnt]," 16
408 Repeat the last "f", "F", "t" or "T" command, but in the opposite
409 search direction.  This is useful if you overshoot.
410 .IP "[cnt]/[string]/<nl>" 16
411 .br
412 Search forward for the next occurrence of "string".
413 Wrap around at the end of the file
414 does occur.
415 The final \fB</>\fR is not required.
416 .IP "[cnt]?[string]?<nl>" 16
417 .br
418 Search backwards for the next occurrence of "string".  If a count is
419 specified, the count becomes the new window size.  Wrap around at the beginning
420 of the file does occur.
421 The final \fB<?>\fR is not required.
422 .IP n 16
423 Repeat the last /[string]/ or ?[string]? search.  Mnemonic: \fBn\fRext
424 occurrence.
425 .IP N 16
426 Repeat the last /[string]/ or ?[string]? search, but in the reverse
427 direction.
428 .IP ":g/[string]/[editor command]<nl>" 16
429 .sp 1
430 Using the \fB:\fR syntax it is possible to do global searches ala the
431 standard UNIX "ed" editor.
432 .LE
433 .NH 2
434 Text Insertion
435 .LP
436 The following commands allow for the insertion of text.  All multicharacter
437 text insertions are terminated with an <esc> character.
438 The last change
439 can always be \fBundone\fR by typing a \fBu\fR.
440 The text insert in insertion mode can contain newlines.
441 .VL 16
442 .IP a{text}<esc> 16
443 Insert text immediately following the cursor position.
444 Mnemonic: \fBa\fRppend
445 .IP A{text}<esc> 16
446 Insert text at the end of the current line.
447 Mnemonic: \fBA\fRppend
448 .IP i{text}<esc> 16
449 Insert text immediately preceding the cursor position.
450 Mnemonic: \fBi\fRnsert
451 .IP I{text}<esc> 16
452 Insert text at the beginning of the current line.
453 .IP o{text}<esc> 16
454 Insert a new line after the line on which the cursor appears and
455 insert text there.  Mnemonic:  \fBo\fRpen new line
456 .IP O{text}<esc> 16
457 Insert a new line preceding the line on which the cursor appears
458 and insert text there.
459 .LE
460 .NH 2
461 Text Deletion
462 .LP
463 The following commands allow the user to delete text in various ways.
464 All changes can always be \fBundone\fR by typing the \fBu\fR command.
465 .VL 16
466 .IP "[cnt]x" 16
467 Delete the character or characters starting at the cursor position.
468 .IP "[cnt]X" 16
469 Delete the character or characters starting at the character preceding
470 the cursor position.
471 .IP "D" 16
472 Deletes the remainder of the line starting at the cursor.
473 Mnemonic: \fBD\fRelete the rest of line
474 .IP "[cnt]d{motion}" 16
475 .br
476 Deletes one or more occurrences of the specified motion.
477 Any motion from sections 4.1 and 4.2 can be used here.
478 The d can be stuttered (e.g. [cnt]dd) to delete cnt lines.
479 .LE
480 .NH 2
481 Text Replacement
482 .LP
483 The following commands allow the user to simultaneously delete and
484 insert new text.  All such actions can be \fBundone\fR by typing
485 \fBu\fR following the command.
486 .VL 16
487 .IP "r<chr>" 16
488 Replaces the character at the current cursor position with <chr>.  This
489 is a one character replacement.  No <esc> is required for termination.
490 Mnemonic:  \fBr\fReplace character
491 .IP "R{text}<esc>" 16
492 Starts overlaying the characters on the screen with whatever you type.
493 It does not stop until an <esc> is typed.
494 .IP "[cnt]s{text}<esc>" 16
495 Substitute for "cnt" characters beginning at the current cursor
496 position.  A "$" will appear at the position in the text where the
497 "cnt"'th character appears so you will know how much you are erasing.
498 Mnemonic: \fBs\fRubstitute
499 .IP "[cnt]S{text}<esc>" 16
500 Substitute for the entire current line (or lines).  If no count is given,
501 a "$" appears at the end of the current line.  If a count of more than
502 1 is given, all the lines to be replaced are deleted before the insertion
503 begins.
504 .IP "[cnt]c{motion}{text}<esc>" 16
505 .br
506 Change the specified "motion" by replacing it with the
507 insertion text.  A "$" will appear at the end of the last item
508 that is being deleted unless the deletion involves whole lines.
509 Motion's can be any motion from sections 4.1 or 4.2.
510 Stuttering the c (e.g. [cnt]cc) changes cnt lines.
511 .LE
512 .NH 2
513 Moving Text
514 .LP
515 \fBVi\fR provides a number of ways of moving chunks of text around.
516 There are nine buffers into which each piece of text which is deleted
517 or "yanked" is put in addition to the "undo" buffer.
518 The most recent deletion or yank is in the "undo" buffer and also
519 usually in buffer
520 1, the next most recent in buffer 2, and so forth.  Each new deletion
521 pushes down all the older deletions.  Deletions older than 9
522 disappear.  There is also
523 a set of named registers, a-z, into which text can optionally
524 be placed.  If any delete or replacement type command is preceded
525 by \fB"<a-z>\fR, that named buffer will contain the text deleted
526 after the command is executed.  For example, \fB"a3dd\fR will delete
527 three lines starting at the current line and put them in buffer \fB"a\fR.*
528 .FS
529 * Referring to an upper case letter as a buffer name (A-Z) is the
530 same as referring to the lower case letter, except that text placed
531 in such a buffer is appended to it instead of replacing it.
532 .FE
533 There are two more basic commands and
534 some variations useful in getting and putting text into a file.
535 .VL 16
536 .IP ["<a-z>][cnt]y{motion} 16
537 .sp 1
538 Yank the specified item or "cnt" items and put in the "undo" buffer or
539 the specified buffer.  The variety of "items" that can be yanked
540 is the same as those that can be deleted with the "d" command or
541 changed with the "c" command.  In the same way that "dd" means
542 delete the current line and "cc" means replace the current line,
543 "yy" means yank the current line.
544 .IP ["<a-z>][cnt]Y 16
545 Yank the current line or the "cnt" lines starting from the current
546 line.  If no buffer is specified, they will go into the "undo" buffer,
547 like any delete would.  It is equivalent to "yy".
548 Mnemonic:  \fBY\fRank
549 .IP ["<a-z>]p 16
550 Put "undo" buffer or the specified buffer down \fBafter\fR the cursor.
551 If whole lines were yanked or deleted into the buffer, then they will be
552 put down on the line following the line the cursor is on.  If
553 something else was deleted, like a word or sentence, then it will
554 be inserted immediately following the cursor.
555 Mnemonic:  \fBp\fRut buffer
556 .IP
557 It should be noted that text in the named buffers remains there when you
558 start editing a new file with the \fB:e file<esc>\fR command.  Since
559 this is so, it is possible to copy or delete text from one file and
560 carry it over to another file in the buffers.
561 However, the undo buffer and the ability to undo are lost when
562 changing files.
563 .IP ["<a-z>]P 16
564 Put "undo" buffer or the specified buffer down \fBbefore\fR the cursor.
565 If whole lines where yanked or deleted into the buffer, then they will be
566 put down on the line preceding the line the cursor is on.  If
567 something else was deleted, like a word or sentence, then it will
568 be inserted immediately preceding the cursor.
569 .IP [cnt]>{motion} 16
570 The shift operator will right shift all the text from the line on which
571 the cursor is located to the line where the \fBmotion\fR is located.
572 The text is shifted by one \fBshiftwidth\fR.  (See section 6.)
573 \fB>>\fR means right shift the current line or lines.
574 .IP [cnt]<{motion} 16
575 The shift operator will left shift all the text from the line on which
576 the cursor is located to the line where the \fBitem\fR is located.
577 The text is shifted by one \fBshiftwidth\fR.  (See section 6.)
578 \fB<<\fR means left shift the current line or lines.
579 Once the line has reached the left margin it is not further affected.
580 .IP [cnt]={motion} 16
581 Prettyprints the indicated area according to
582 .B lisp
583 conventions.
584 The area should be a lisp s-expression.
585 .LE
586 .NH 2
587 Miscellaneous Commands
588 .LP
589 \fBVi\fR has a number of miscellaneous commands that are very
590 useful.  They are:
591 .VL 16
592 .IP ZZ 16
593 This is the normal way to exit from vi.
594 If any changes have been made, the file is written out.
595 Then you are returned to the shell.
596 .IP ^L 16
597 Redraw the current screen.  This is useful if someone "write"s you
598 while you are in "vi" or if for any reason garbage gets onto the
599 screen.
600 .IP ^R 16
601 On dumb terminals, those not having the "delete line" function
602 (the vt100 is such a terminal), \fBvi\fR saves redrawing the
603 screen when you delete a line by just marking the line with an
604 "@" at the beginning and blanking the line.  If you want to
605 actually get rid of the lines marked with "@" and see what the
606 page looks like, typing a ^R will do this.
607 .IP \s+4.\s0 16
608 "Dot" is a particularly useful command.  It repeats the last
609 text modifying command.  Therefore you can type a command once and
610 then to another place and repeat it by just typing ".".
611 .IP u 16
612 Perhaps the most important command in the editor,
613 u undoes the last command that changed the buffer.
614 Mnemonic:  \fBu\fRndo
615 .IP U 16
616 Undo all the text modifying commands performed on the current line
617 since the last time you moved onto it.
618 .IP [cnt]J 16
619 Join the current line and the following line.  The <nl> is deleted
620 and the two lines joined, usually with a space between the
621 end of the first line and the beginning of what was the second
622 line.  If the first line ended with a "period", then two spaces
623 are inserted.
624 A count joins the next cnt lines.
625 Mnemonic: \fBJ\fRoin lines
626 .IP Q 16
627 Switch to \fBex\fR editing mode.
628 In this mode \fBvi\fR will behave very much like \fBed\fR.
629 The editor in this mode will operate on single lines normally and
630 will not attempt to keep the "window" up to date.
631 Once in this mode it is also possible to switch to the \fBopen\fR
632 mode of editing.  By entering the command \fB[line number]open<nl>\fR
633 you enter this mode.  It is similar to the normal visual mode
634 except the window is only \fBone\fR line long.
635 Mnemonic: \fBQ\fRuit visual mode
636 .IP ^] 16
637 An abbreviation for a tag command.
638 The cursor should be positioned at the beginning of a word.
639 That word is taken as a tag name, and the tag with that
640 name is found as if it had been typed in a :tag command.
641 .IP [cnt]!{motion}{UNIX\ cmd}<nl> 16
642 .br
643 Any UNIX filter
644 (e.g. command that reads the standard input and outputs something
645 to the standard output) can be sent a section of the current file and
646 have the output of the command replace the original text.  Useful
647 examples are programs like \fBcb\fR, \fBsort\fR, and
648 \fBnroff\fR.  For instance, using \fBsort\fR it would be possible to
649 sort a section of the current file into a new list.
650 Using \fB!!\fR means take a line or lines starting at the line the
651 cursor is currently on and pass them to the UNIX command.
652 .B NOTE:
653 To just escape to the shell for one command,
654 use :!{cmd}<nl>, see section 5.
655 .IP z{cnt}<nl> 16
656 This resets the current window size to "cnt" lines and redraws the screen.
657 .LE
658 .NH 2
659 Special Insert Characters
660 .LP
661 There are some characters that have special meanings during
662 insert modes.  They are:
663 .VL 16
664 .IP ^V 16
665 During inserts, typing a ^V allows you to quote control characters
666 into the file.  Any character typed after the ^V will be inserted
667 into the file.
668 .IP [^]^D\ or\ [0]^D 16
669 <^D> without any argument backs up one \fBshiftwidth\fR.  This is necessary
670 to remove indentation that was inserted by the \fBautoindent\fR feature.
671 ^<^D> temporarily removes all the autoindentation, thus placing the cursor
672 at the left margin.  On the next line, the previous indent level will be
673 restored.  This is useful for putting "labels" at the left margin.
674 0<^D> says remove all autoindents and stay that way.  Thus the cursor
675 moves to the left margin and stays there on successive lines until
676 <tab>'s are typed.  As with the <tab>, the <^D> is only effective before
677 any other "non-autoindent" controlling characters are typed.
678 Mnemonic: \fBD\fRelete a shiftwidth
679 .IP ^W 16
680 If the cursor is sitting on a word, <^W> moves the cursor back to the beginning
681 of the word, thus erasing the word from the insert.
682 Mnemonic: erase \fBW\fRord
683 .IP <bs> 16
684 The backspace always serves as an erase during insert modes in addition
685 to your normal "erase" character.  To insert a <bs> into your file, use
686 the <^V> to quote it.
687 .LE
688 .NH 1
689 \fB:\fR Commands
690 .LP
691 Typing a ":" during command mode causes \fBvi\fR to put the cursor at
692 the bottom on the screen in preparation for a command.  In the
693 ":" mode, \fBvi\fR can be given most \fBed\fR commands.  It is
694 also from this mode that you exit from \fBvi\fR or switch to different
695 files.  All commands of this variety are terminated by a <nl>, <cr>,
696 or <esc>.
697 .VL 16
698 .IP ":w[!] [file]" 16
699 Causes \fBvi\fR to write out the current text to the disk.  It is
700 written to the file you are editing unless "file" is supplied.  If
701 "file" is supplied, the write is directed to that file instead.  If
702 that file already exists, \fBvi\fR will not perform the write unless
703 the "!" is supplied indicating you
704 .I really
705 want to destroy the older copy of the file.
706 .IP :q[!] 16
707 Causes \fBvi\fR to exit.  If you have modified the file you are
708 looking at currently and haven't written it out, \fBvi\fR will
709 refuse to exit unless the "!" is supplied.
710 .IP ":e[!] [+[cmd]] [file]" 16
711 .sp 1
712 Start editing a new file called "file" or start editing the current
713 file over again.  The command ":e!" says "ignore the changes I've made
714 to this file and start over from the beginning".  It is useful if
715 you really mess up the file.  The optional "+" says instead of starting
716 at the beginning, start at the "end", or,
717 if "cmd" is supplied, execute "cmd" first.
718 Useful cases of this are where cmd is "n" (any integer) which starts
719 at line number n,
720 and "/text", which searches for "text" and starts at the line where
721 it is found.
722 .IP "^^" 16
723 Switch back to the place you were before your last tag command.
724 If your last tag command stayed within the file, ^^ returns to that tag.
725 If you have no recent tag command, it will return to the
726 same place in the previous file that it was showing when you switched
727 to the current file.
728 .IP ":n[!]" 16
729 Start editing the next file in the argument list.  Since \fBvi\fR
730 can be called with multiple file names, the ":n" command tells it to
731 stop work on the current file and switch to the next file.  If the
732 current file was modifies, it has to be written out before the ":n"
733 will work or else the "!" must be supplied, which says discard the
734 changes I made to the current file.
735 .IP ":n[!] file [file file ...]" 16
736 .sp
737 Replace the current argument list with a new list of files and start
738 editing the first file in this new list.
739 .IP ":r file" 16
740 Read in a copy of "file" on the line after the cursor.
741 .IP ":r !cmd" 16
742 Execute the "cmd" and take its output and put it into the file after
743 the current line.
744 .IP ":!cmd" 16
745 Execute any UNIX shell command.
746 .IP ":ta[!] tag" 16
747 .B Vi
748 looks in the file named
749 .B tags
750 in the current directory.
751 .B Tags
752 is a file of lines in the format:
753 .sp 1
754 .ti +8
755 tag filename \fBvi\fR-search-command
756 .sp 1
757 If \fBvi\fR finds the tag you specified in the \fB:ta\fR command,
758 it stops editing the current file if necessary and if the current file is
759 up to date on the disk and switches to the file specified and uses the
760 search pattern specified to find the "tagged" item of interest.  This
761 is particularly useful when editing multi-file C programs such as the
762 operating system.  There is a program called \fBctags\fR which will
763 generate an appropriate \fBtags\fR file for C and f77
764 programs so that by saying
765 \fB:ta function<nl>\fR you will be switched to that function.
766 It could also be useful when editing multi-file documents, though the
767 \fBtags\fR file would have to be generated manually.
768 .LE
769 .NH 1
770 Special Arrangements for Startup
771 .PP
772 \fBVi\fR takes the value of \fB$TERM\fR and looks up the characteristics
773 of that terminal in the file \fB/etc/termcap\fR.
774 If you don't know \fBvi\fR's name for the terminal you are working
775 on, look in \fB/etc/termcap\fR.
776 .PP
777 When \fBvi\fR starts, it attempts to read the variable EXINIT
778 from your environment.*
779 If that exists, it takes the values in it as the default values
780 for certain of its internal constants.  See the section on "Set Values"
781 for further details.
782 If EXINIT doesn't exist you will get all the normal defaults.
783 .FS
784 * On version 6 systems
785 Instead of EXINIT, put the startup commands in the file .exrc
786 in your home directory.
787 .FE
788 .PP
789 Should you inadvertently hang up the phone while inside
790 .B vi ,
791 or should the computer crash,
792 all may not be lost.
793 Upon returning to the system, type:
794 .DS
795 vi \-r file
796 .DE
797 This will normally recover the file.  If there is more than one
798 temporary file for a specific file name, \fBvi\fR recovers the
799 newest one.  You can get an older version by recovering the
800 file more than once.
801 The command "vi -r" without a file name gives you the list of files
802 that were saved in the last system crash
803 (but
804 .I not
805 the file just saved when the phone was hung up).
806 .NH 1
807 Set Commands
808 .LP
809 \fBVi\fR has a number of internal variables and switches which can be
810 set to achieve special affects.
811 These options come in three forms, those that are switches, which toggle
812 from off to on and back, those that require a numeric value, and those
813 that require an alphanumeric string value.
814 The toggle options are set by a command of the form:
815 .DS
816 :set option<nl>
817 .DE
818 and turned off with the command:
819 .DS
820 :set nooption<nl>
821 .DE
822 Commands requiring a value are set with a command of the form:
823 .DS
824 :set option=value<nl>
825 .DE
826 To display the value of a specific option type:
827 .DS
828 :set option?<nl>
829 .DE
830 To display only those that you have changed type:
831 .DS
832 :set<nl>
833 .DE
834 and to display the long table of all the settable parameters and
835 their current values type:
836 .DS
837 :set all<nl>
838 .DE
839 .PP
840 Most of the options have a long form and an abbreviation.  Both are
841 listed in the following table as well as the normal default value.
842 .PP
843 To arrange to have values other than the default used every time you
844 enter
845 .B vi ,
846 place the appropriate
847 .B set
848 command in EXINIT in your environment, e.g.
849 .DS
850 EXINIT='set ai aw terse sh=/bin/csh'
851 export EXINIT
852 .DE
853 or
854 .DS
855 setenv EXINIT 'set ai aw terse sh=/bin/csh'
856 .DE
857 for
858 .B sh
859 and
860 .B csh ,
861 respectively.
862 These are usually placed in your .profile or .login.
863 If you are running a system without environments (such as version 6)
864 you can place the set command in the file .exrc in your home
865 directory.
866 .VL 16
867 .IP autoindent\ ai 16
868 Default: noai Type: toggle
869 .br
870 When in autoindent mode, vi helps you indent code by starting each
871 line in the same column as the preceding line.
872 Tabbing to the right with <tab> or <^T> will move this boundary to
873 the right, and it can be moved to the left with <^D>.
874 .IP autoprint\ ap 16
875 Default: ap Type: toggle
876 .br
877 Causes the current line to be printed after each ex text modifying command.
878 This is not of much interest in the normal \fBvi\fR visual mode.
879 .IP autowrite\ aw 16
880 Default: noaw type: toggle
881 .br
882 Autowrite causes an automatic write to be done if there are unsaved
883 changes before certain commands which change files or otherwise
884 interact with the outside world.
885 These commands are :!, :tag, :next, :rewind, ^^, and ^].
886 .IP beautify\ bf 16
887 Default: nobf Type: toggle
888 .br
889 Causes all control characters except <tab>, <nl>, and <ff> to be discarded.
890 .IP directory\ dir 16
891 Default: dir=/tmp Type: string
892 .br
893 This is the directory in which \fBvi\fR puts its temporary file.
894 .IP errorbells\ eb 16
895 Default: noeb Type: toggle
896 .br
897 Error messages are preceded by a <bell>.
898 .IP hardtabs\ ht 16
899 Default: hardtabs=8 Type: numeric
900 .br
901 This option contains the value of hardware tabs in your terminal, or
902 of software tabs expanded by the Unix system.
903 .IP ignorecase\ ic 16
904 Default: noic Type: toggle
905 .br
906 All upper case characters are mapped to lower case in regular expression
907 matching.
908 .IP lisp 16
909 Default: nolisp Type: toggle
910 .br
911 Autoindent for \fBlisp\fR code.  The commands \fB( ) [[\fR and \fB]]\fR
912 are modified appropriately to affect s-expressions and functions.
913 .IP list 16
914 Default: nolist Type: toggle
915 .br
916 All printed lines have the <tab> and <nl> characters displayed visually.
917 .IP magic 16
918 Default: magic Type: toggle
919 .br
920 Enable the metacharacters for matching.  These include \fB. * < > [string]
921 [^string]\fR and \fB[<chr>-<chr>]\fR.
922 .IP number\ nu 16
923 Default: nonu Type: toggle
924 .br
925 Each line is displayed with its line number.
926 .IP open 16
927 Default: open Type: toggle
928 .br
929 When set, prevents entering open or visual modes from ex or edit.
930 Not of interest from vi.
931 .IP optimize\ opt 16
932 Default: opt Type: toggle
933 .br
934 Basically of use only when using the \fBex\fR capabilities.  This
935 option prevents automatic <cr>s from taking place,
936 and speeds up output of indented lines,
937 at the expense of losing typeahead on some versions of UNIX.
938 .IP paragraphs\ para 16
939 Default: para=IPLPPPQPP\ bp Type: string
940 .br
941 Each pair of characters in the string indicate \fBnroff\fR macros
942 which are to be treated as the beginning of a paragraph for the
943 \fB{\fR and \fB}\fR commands.  The default string is for the \fB-ms\fR
944 and \fB-mm\fR macros.
945 To indicate one letter \fBnroff\fR macros, such as \fB.P\fR or \fB.H\fR,
946 quote a space in for the second character position.  For example:
947 .sp 1
948 .ti +8
949 :set paragraphs=P\e bp<nl>
950 .sp 1
951 would cause \fBvi\fR to consider \fB.P\fR and \fB.bp\fR as paragraph
952 delimiters.
953 .IP prompt 16
954 Default: prompt Type: toggle
955 .br
956 In
957 .B ex
958 command mode the prompt character \fB:\fR will be printed when
959 \fBex\fR is waiting for a command.  This is not of interest from vi.
960 .IP redraw 16
961 Default: noredraw Type: toggle
962 .br
963 On dumb terminals, force the screen to always be up to date,
964 by sending great amounts of output.  Useful only at high speeds.
965 .IP report 16
966 Default: report=5 Type: numeric
967 .br
968 This sets the threshold for the number of lines modified.  When
969 more than this number of lines are modified, removed, or yanked,
970 \fBvi\fR will report the number of lines changed at the bottom of
971 the screen.
972 .IP scroll 16
973 Default: scroll={1/2 window} Type: numeric
974 .br
975 This is the number of lines that the screen scrolls up or down when
976 using the <^U> and <^D> commands.
977 .IP sections 16
978 Default: sections=SHNHH HU Type: string
979 .br
980 Each two character pair of this string specify \fBnroff\fR macro names
981 which are to be treated as the beginning of a section by the
982 \fB]]\fR and \fB[[\fR commands.  The default string is for the \fB-ms\fR
983 and \fB-mm\fR macros.
984 To enter one letter \fBnroff\fR macros, use a quoted space as the
985 second character.
986 See \fBparagraphs\fR for a fuller explanation.
987 .IP shell\ sh 16
988 Default: sh=from environment SHELL or /bin/sh   Type: string
989 .br
990 This is the name of the \fBsh\fR to be used for "escaped" commands.
991 .IP shiftwidth\ sw 16
992 Default: sw=8 Type: numeric
993 .br
994 This is the number of spaces that a <^T> or <^D> will move over for
995 indenting, and the amount < and > shift by.
996 .IP showmatch\ sm 16
997 Default: nosm Type: toggle
998 .br
999 When a \fB)\fR or \fB}\fR is typed, show the matching \fB(\fR or \fB{\fR
1000 by moving the cursor to it for one second if it is on the current screen.
1001 .IP slowopen\ slow 16
1002 Default: terminal dependent Type: toggle
1003 .br
1004 On terminals that are slow and unintelligent, this option prevents the
1005 updating of the screen some of the time to improve speed.
1006 .IP tabstop\ ts 16
1007 Default: ts=8 Type: numeric
1008 .br
1009 <tab>s are expanded to boundaries that are multiples of this value.
1010 .IP taglength\ tl 16
1011 Default: tl=0 Type: numeric
1012 .br
1013 If nonzero, tag names are only significant to this many characters.
1014 .IP term 16
1015 Default: (from environment \fBTERM\fP, else dumb) Type: string
1016 .br
1017 This is the terminal and controls the visual displays.  It cannot be
1018 changed when in "visual" mode,
1019 you have to Q to command mode, type a
1020 set term command, and do ``vi.'' to get back into visual.
1021 Or exit vi, fix $TERM, and reenter.
1022 The definitions that drive a particular
1023 terminal type are found in the file \fB/etc/termcap\fR.
1024 .IP terse 16
1025 Default: terse Type: toggle
1026 .br
1027 When set, the error diagnostics are short.
1028 .IP warn 16
1029 Default: warn Type: toggle
1030 .br
1031 The user is warned if she/he tries to escape to
1032 the shell without writing out the current changes.
1033 .IP window 16
1034 Default: window={8 at 600 baud or less, 16 at 1200 baud, and screen
1035 size \- 1 at 2400 baud or more} Type: numeric
1036 .br
1037 This is the number of lines in the window whenever \fBvi\fR must redraw
1038 an entire screen.  It is useful to make this size smaller if you are
1039 on a slow line.
1040 .IP w300,\ w1200,\ w9600
1041 .br
1042 These set window, but only within the corresponding speed ranges.
1043 They are useful in an EXINIT to fine tune window sizes.
1044 For example,
1045 .DS
1046 set w300=4 w1200=12
1047 .DE
1048 causes a 4 lines window at speed up to 600 baud, a 12 line window at 1200
1049 baud, and a full screen (the default) at over 1200 baud.
1050 .IP wrapscan\ ws 16
1051 Default: ws Type: toggle
1052 .br
1053 Searches will wrap around the end of the file when is option is set.  When
1054 it is off, the search will terminate when it reaches the end or the
1055 beginning of the file.
1056 .IP wrapmargin\ wm 16
1057 Default: wm=0 Type: numeric
1058 .br
1059 \fBVi\fR will automatically insert a <nl> when it finds a natural
1060 break point (usually a <sp> between words) that occurs within
1061 "wm" spaces of the right margin.
1062 Therefore with "wm=0" the option is off.  Setting it to 10 would
1063 mean that any time you are within 10 spaces of the right margin
1064 \fBvi\fR would be looking for a <sp> or <tab> which it could
1065 replace with a <nl>.  This is convenient for people who forget
1066 to look at the screen while they type.
1067 (In version 3, wrapmargin behaves more like nroff, in that the
1068 boundary specified by the distance from the right edge of the screen
1069 is taken as the rightmost edge of the area where a break is allowed,
1070 instead of the leftmost edge.)
1071 .IP writeany\ wa 16
1072 Default: nowa Type: toggle
1073 .br
1074 \fBVi\fR normally makes a number of checks before it writes out a file.
1075 This prevents the user from inadvertently destroying a file.  When the
1076 "writeany" option is enabled, \fBvi\fR no longer makes these checks.
1077 .LE