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