home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / share / doc / usd / 15.vi / vi.apwh.ms < prev    next >
Encoding:
Text File  |  1991-04-17  |  39.8 KB  |  1,080 lines

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