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