home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / docs / USD.doc / vitut / vi.in < prev    next >
Text File  |  1996-08-18  |  79KB  |  2,075 lines

  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.in    8.5 (Berkeley) 8/18/96
  33. .\"
  34. .nr LL 6.5i
  35. .nr FL 6.5i
  36. .EH 'USD:11-%''An Introduction to Display Editing with Vi'
  37. .OH 'An Introduction to Display Editing with Vi''USD:11-%'
  38. .bd S 3
  39. .if t .ds dg \(dg
  40. .if n .ds dg +
  41. .if t .ds dd \(dd
  42. .if n .ds dd ++
  43. .\".RP
  44. .TL
  45. An Introduction to Display Editing with Vi
  46. .AU
  47. William Joy
  48. .AU
  49. Mark Horton
  50. .AI
  51. Computer Science Division
  52. Department of Electrical Engineering and Computer Science
  53. University of California, Berkeley
  54. Berkeley, Ca.  94720
  55. .AB
  56. .PP
  57. .I Vi
  58. (visual) is a display oriented interactive text editor.
  59. When using
  60. .I vi
  61. the screen of your terminal acts as a window into the file which you
  62. are editing.  Changes which you make to the file are reflected
  63. in what you see.
  64. .PP
  65. Using
  66. .I vi
  67. you can insert new text any place in the file quite easily.
  68. Most of the commands to
  69. .I vi
  70. move the cursor around in the file.
  71. There are commands to move the cursor
  72. forward and backward in units of characters, words,
  73. sentences and paragraphs.
  74. A small set of operators, like
  75. .B d
  76. for delete and
  77. .B c
  78. for change, are combined with the motion commands to form operations
  79. such as delete word or change paragraph, in a simple and natural way.
  80. This regularity and the mnemonic assignment of commands to keys makes the
  81. editor command set easy to remember and to use.
  82. .PP
  83. .I Vi
  84. will work on a large number of display terminals,
  85. and new terminals are easily driven after editing a terminal description file.
  86. While it is advantageous to have an intelligent terminal which can locally
  87. insert and delete lines and characters from the display, the editor will
  88. function quite well on dumb terminals over slow phone lines.
  89. The editor makes allowance for the low bandwidth in these situations
  90. and uses smaller window sizes and
  91. different display updating algorithms to make best use of the
  92. limited speed available.
  93. .PP
  94. It is also possible to use the command set of
  95. .I vi
  96. on hardcopy terminals, storage tubes and ``glass tty's'' using a one line
  97. editing window; thus
  98. .I vi's
  99. command set is available on all terminals.
  100. The full command set of the more traditional, line
  101. oriented editor
  102. .I ex
  103. is available within
  104. .I vi;
  105. it is quite simple to switch between the two modes of editing.
  106. .AE
  107. .NH 1
  108. Getting started
  109. .PP
  110. .FS
  111. The financial support of an \s-2IBM\s0 Graduate Fellowship and the
  112. National Science Foundation under grants MCS74-07644-A03 and MCS78-07291
  113. is gratefully acknowledged.
  114. .FE
  115. This document provides a quick introduction to
  116. .I vi.
  117. (Pronounced \fIvee-eye\fP.)
  118. You should be running
  119. .I vi
  120. on a file you are familiar with while you are reading this.
  121. The first part of this document (sections 1 through 5)
  122. describes the basics of using
  123. .I vi.
  124. Some topics of special interest are presented in section 6, and 
  125. some nitty-gritty details of how the editor functions are saved for section
  126. 7 to avoid cluttering the presentation here.
  127. .PP
  128. There is also a short appendix here, which gives for each character the
  129. special meanings which this character has in \fIvi\fR.  Attached to
  130. this document should be a quick reference card.
  131. This card summarizes the commands of
  132. .I vi
  133. in a very compact format.  You should have the card handy while you are
  134. learning
  135. .I vi.
  136. .NH 2
  137. Specifying terminal type
  138. .PP
  139. Before you can start
  140. .I vi
  141. you must tell the system what kind of terminal you are using.
  142. Here is a (necessarily incomplete) list of terminal type codes.
  143. If your terminal does not appear here, you should consult with one of
  144. the staff members on your system to find out the code for your terminal.
  145. If your terminal does not have a code, one can be assigned and a description
  146. for the terminal can be created.
  147. .LP
  148. .TS
  149. center;
  150. ab ab ab
  151. a a a.
  152. Code    Full name    Type
  153. _
  154. 2621    Hewlett-Packard 2621A/P    Intelligent
  155. 2645    Hewlett-Packard 264x    Intelligent
  156. act4    Microterm ACT-IV    Dumb
  157. act5    Microterm ACT-V    Dumb
  158. adm3a    Lear Siegler ADM-3a    Dumb
  159. adm31    Lear Siegler ADM-31    Intelligent
  160. c100    Human Design Concept 100    Intelligent
  161. dm1520    Datamedia 1520    Dumb
  162. dm2500    Datamedia 2500    Intelligent
  163. dm3025    Datamedia 3025    Intelligent
  164. fox    Perkin-Elmer Fox    Dumb
  165. h1500    Hazeltine 1500    Intelligent
  166. h19    Heathkit h19    Intelligent
  167. i100    Infoton 100    Intelligent
  168. mime    Imitating a smart act4    Intelligent
  169. t1061    Teleray 1061    Intelligent
  170. vt52    Dec VT-52    Dumb
  171. .TE
  172. .PP
  173. Suppose for example that you have a Hewlett-Packard HP2621A
  174. terminal.  The code used by the system for this terminal is `2621'.
  175. In this case you can use one of the following commands to tell the system
  176. the type of your terminal:
  177. .DS
  178. % \fBsetenv TERM\fP 2621
  179. .DE
  180. This command works with the
  181. .I csh
  182. shell.
  183. If you are using the standard Bourne shell
  184. .I sh
  185. then you should give the commands
  186. .DS
  187. $ \fBTERM=\fP2621
  188. $ \fBexport TERM\fP
  189. .DE
  190. .PP
  191. If you want to arrange to have your terminal type set up automatically
  192. when you log in, you can use the
  193. .I tset
  194. program.
  195. If you dial in on a
  196. .I mime ,
  197. but often use hardwired ports, a typical line for your
  198. .I .login
  199. file (if you use csh) would be
  200. .DS
  201. \fBsetenv TERM \(gatset\fP \- \-d mime\(ga
  202. .DE
  203. or for your
  204. .I .profile
  205. file (if you use sh)
  206. .DS
  207. \fBTERM=\(gatse\fPt \- \-d mime\(ga
  208. .DE
  209. .I Tset
  210. knows which terminals are hardwired to each port
  211. and needs only to be told that when you dial in you
  212. are probably on a
  213. .I mime .
  214. .I Tset
  215. is usually used to change the erase and kill characters, too.
  216. .NH 2
  217. Editing a file
  218. .PP
  219. After telling the system which kind of terminal you have, you should
  220. make a copy of a file you are familiar with, and run
  221. .I vi
  222. on this file, giving the command
  223. .DS
  224. % \fBvi\fR \fIname\fR
  225. .DE
  226. replacing \fIname\fR with the name of the copy file you just created.
  227. The screen should clear and the text of your file should appear on the
  228. screen.  If something else happens refer to the footnote.\*(dd
  229. .FS
  230. \*(dd If you gave the system an incorrect terminal type code then the
  231. editor may have just made a mess out of your screen.  This happens when
  232. it sends control codes for one kind of terminal to some other
  233. kind of terminal.  In this case hit
  234. the keys \fB:q\fR (colon and the q key) and then hit the \s-2RETURN\s0 key.
  235. This should get you back to the command level interpreter.
  236. Figure out what you did wrong (ask someone else if necessary) and try again.
  237.      Another thing which can go wrong is that you typed the wrong file name and
  238. the editor just printed an error diagnostic.  In this case you should
  239. follow the above procedure for getting out of the editor, and try again
  240. this time spelling the file name correctly.
  241.      If the editor doesn't seem to respond to the commands which you type
  242. here, try sending an interrupt to it by hitting the \s-2DEL\s0 or \s-2RUB\s0
  243. key on your terminal, and then hitting the \fB:q\fR command again followed
  244. by a carriage return.
  245. .sp
  246. .FE
  247. .NH 2
  248. The editor's copy: the buffer
  249. .PP
  250. The editor does not directly modify the file which you are editing. 
  251. Rather, the editor makes a copy of this file, in a place called the
  252. .I buffer,
  253. and remembers the file's
  254. name.  You do not affect the contents of the file unless and until you
  255. write the changes you make back into the original file.
  256. .NH 2
  257. Notational conventions
  258. .PP
  259. In our examples, input which must be typed as is will be presented in
  260. \fBbold face\fR. Text which should be replaced with appropriate input
  261. will be given in \fIitalics\fR.  We will represent special characters
  262. in \s-2SMALL CAPITALS\s0.
  263. .NH 2
  264. Arrow keys
  265. .PP
  266. The editor command set is independent of the terminal
  267. you are using.  On most terminals with cursor positioning keys, these keys
  268. will also work within the editor.
  269. If you don't have cursor positioning keys, or even if you do, you can use
  270. the \fBh j k\fR and \fBl\fR keys as cursor positioning
  271. keys (these are labelled with arrows on an
  272. .I adm3a).*
  273. .PP
  274. (Particular note for the HP2621: on this terminal the function keys
  275. must be \fIshifted\fR (ick) to send to the machine, otherwise they
  276. only act locally.  Unshifted use will leave the cursor positioned
  277. incorrectly.)
  278. .FS
  279. * As we will see later,
  280. .I h
  281. moves back to the left (like control-h which is a backspace),
  282. .I j
  283. moves down (in the same column),
  284. .I k
  285. moves up (in the same column),
  286. and
  287. .I l
  288. moves to the right.
  289. .FE
  290. .NH 2
  291. Special characters: \s-2ESC\s0, \s-2CR\s0 and \s-2DEL\s0
  292. .PP
  293. Several of these special characters are very important, so be sure to
  294. find them right now.  Look on your keyboard for a key labelled \s-2ESC\s0
  295. or \s-2ALT\s0.  It should be near the upper left corner of your terminal.
  296. Try hitting this key a few times.  The editor will ring the bell
  297. to indicate that it is in a quiescent state.\*(dd
  298. .FS
  299. \*(dd On smart terminals where it is possible, the editor will quietly
  300. flash the screen rather than ringing the bell.
  301. .FE
  302. Partially formed commands are cancelled by \s-2ESC\s0, and when you insert
  303. text in the file you end the text insertion
  304. with \s-2ESC\s0.  This key is a fairly
  305. harmless one to hit, so you can just hit it if you don't know
  306. what is going on until the editor rings the bell.
  307. .PP
  308. The \s-2CR\s0 or \s-2RETURN\s0 key is important because it is used
  309. to terminate certain commands.
  310. It is usually at the right side of the keyboard,
  311. and is the same command used at the end of each shell command.
  312. .PP
  313. Another very useful key is the \s-2DEL\s0 or \s-2RUB\s0 key, which generates
  314. an interrupt, telling the editor to stop what it is doing.
  315. It is a forceful way of making the editor listen
  316. to you, or to return it to the quiescent state if you don't know or don't
  317. like what is going on.  Try hitting the `/' key on your terminal.  This
  318. key is used when you want to specify a string to be searched for.  The
  319. cursor should now be positioned at the bottom line of the terminal after
  320. a `/' printed as a prompt.  You can get the cursor back to the current
  321. position by hitting the \s-2DEL\s0 or \s-2RUB\s0 key; try this now.*
  322. .FS
  323. * Backspacing over the `/' will also cancel the search.
  324. .FE
  325. From now on we will simply refer to hitting the \s-2DEL\s0 or \s-2RUB\s0
  326. key as ``sending an interrupt.''**
  327. .FS
  328. ** On some systems, this interruptibility comes at a price: you cannot type
  329. ahead when the editor is computing with the cursor on the bottom line.
  330. .FE
  331. .PP
  332. The editor often echoes your commands on the last line of the terminal.
  333. If the cursor is on the first position of this last line, then the editor
  334. is performing a computation, such as computing a new position in the
  335. file after a search or running a command to reformat part of the buffer.
  336. When this is happening you can stop the editor by
  337. sending an interrupt.
  338. .NH 2
  339. Getting out of the editor
  340. .PP
  341. After you have worked with this introduction for a while, and you wish
  342. to do something else, you can give the command \fBZZ\fP
  343. to the editor.
  344. This will write the contents of the editor's buffer back into
  345. the file you are editing, if you made any changes, and then quit from
  346. the editor.  You can also end an editor
  347. session by giving the command \fB:q!\fR\s-2CR\s0;\*(dg
  348. .FS
  349. \*(dg All commands which read from the last display line can also be
  350. terminated with a \s-2ESC\s0 as well as an \s-2CR\s0.
  351. .FE
  352. this is a dangerous but occasionally essential
  353. command which ends the editor session and discards all your changes.
  354. You need to know about this command in case you change the editor's
  355. copy of a file you wish only to look at.  Be very careful
  356. not to give this command when you really want to save
  357. the changes you have made.
  358. .NH 1
  359. Moving around in the file
  360. .NH 2
  361. Scrolling and paging
  362. .PP
  363. The editor has a number of commands for moving around in the file.
  364. The most useful of these is generated by hitting the control and D keys
  365. at the same time, a control-D or `^D'.  We will use this two character
  366. notation for referring to these control keys from now on.  You may have
  367. a key labelled `^' on your terminal.  This key will be represented as `\(ua'
  368. in this document; `^' is exclusively used as part of the `^x' notation
  369. for control characters.\*(dd
  370. .FS
  371. \*(dd If you don't have a `^' key on your terminal
  372. then there is probably a key labelled `\(ua'; in any case these characters
  373. are one and the same.
  374. .FE
  375. .PP
  376. As you know now if you tried hitting \fB^D\fR, this command scrolls down in
  377. the file.  The \fBD\fR thus stands for down.  Many editor commands are mnemonic
  378. and this makes them much easier to remember.  For instance the command
  379. to scroll up is \fB^U\fR.  Many dumb terminals can't scroll up at all, in which
  380. case hitting \fB^U\fR clears the screen and refreshes it
  381. with a line which is farther back in the file at the top.
  382. .PP
  383. If you want to see more of the file below where you are, you can
  384. hit \fB^E\fR to expose one more line at the bottom of the screen,
  385. leaving the cursor where it is.
  386. The command \fB^Y\fR (which is hopelessly non-mnemonic, but next to \fB^U\fR
  387. on the keyboard) exposes one more line at the top of the screen.
  388. .PP
  389. There are other ways to move around in the file; the keys \fB^F\fR and \fB^B\fR
  390. move forward and backward a page,
  391. keeping a couple of lines of continuity between screens
  392. so that it is possible to read through a file using these rather than
  393. \fB^D\fR and \fB^U\fR if you wish.
  394. .PP
  395. Notice the difference between scrolling and paging.  If you are trying
  396. to read the text in a file, hitting \fB^F\fR to move forward a page
  397. will leave you only a little context to look back at.  Scrolling on the
  398. other hand leaves more context, and happens more smoothly.  You can continue
  399. to read the text as scrolling is taking place.
  400. .NH 2
  401. Searching, goto, and previous context
  402. .PP
  403. Another way to position yourself in the file is by giving the editor a string
  404. to search for.  Type the character \fB/\fR followed by a string of characters
  405. terminated by \s-2CR\s0.  The editor will position the cursor
  406. at the next occurrence of this string.
  407. Try hitting \fBn\fR to then go to the next occurrence of this string.
  408. The character \fB?\fR will search backwards from where you are, and is
  409. otherwise like \fB/\fR.\*(dg
  410. .FS
  411. \*(dg These searches will normally wrap around the end of the file, and thus
  412. find the string even if it is not on a line in the direction you search
  413. provided it is anywhere else in the file.  You can disable this wraparound
  414. in scans by giving the command \fB:se nowrapscan\fR\s-2CR\s0,
  415. or more briefly \fB:se nows\fR\s-2CR\s0.
  416. .FE
  417. .PP
  418. If the search string you give the editor is not present in the
  419. file the editor will print
  420. a diagnostic on the last line of the screen, and the cursor will be returned
  421. to its initial position.
  422. .PP
  423. If you wish the search to match only at the beginning of a line, begin
  424. the search string with an \fB\(ua\fR.  To match only at the end of
  425. a line, end the search string with a \fB$\fR.
  426. Thus \fB/\(uasearch\fR\s-2CR\s0 will search for the word `search' at
  427. the beginning of a line, and \fB/last$\fR\s-2CR\s0 searches for the
  428. word `last' at the end of a line.*
  429. .FS
  430. *Actually, the string you give to search for here can be a
  431. .I "regular expression"
  432. in the sense of the editors
  433. .I ex (1)
  434. and
  435. .I ed (1).
  436. If you don't wish to learn about this yet, you can disable this more
  437. general facility by doing
  438. \fB:se\ nomagic\fR\s-2CR\s0;
  439. by putting this command in
  440. EXINIT
  441. in your environment, you can have this always be in effect (more
  442. about
  443. .I EXINIT
  444. later.)
  445. .FE
  446. .PP
  447. The command \fBG\fR, when preceded by a number will position the cursor
  448. at that line in the file.
  449. Thus \fB1G\fR will move the cursor to
  450. the first line of the file.  If you give \fBG\fR no count, then it moves
  451. to the end of the file.
  452. .PP
  453. If you are near the end of the file, and the last line is not at the bottom
  454. of the screen, the editor will place only the character `~' on each remaining
  455. line.  This indicates that the last line in the file is on the screen;
  456. that is, the `~' lines are past the end of the file.
  457. .PP
  458. You can find out the state of the file you are editing by typing a \fB^G\fR.
  459. The editor will show you the name of the file you are editing, the number
  460. of the current line, the number of lines in the buffer, and the percentage
  461. of the way through the buffer which you are.
  462. Try doing this now, and remember the number of the line you are on.
  463. Give a \fBG\fR command to get to the end and then another \fBG\fR command
  464. to get back where you were.
  465. .PP
  466. You can also get back to a previous position by using the command
  467. \fB\(ga\(ga\fR (two back quotes).
  468. This is often more convenient than \fBG\fR because it requires no advance
  469. preparation.
  470. Try giving a \fBG\fR or a search with \fB/\fR or \fB?\fR and then a
  471. \fB\(ga\(ga\fR to get back to where you were.  If you accidentally hit
  472. \fBn\fR or any command which moves you far away from a context of interest, you
  473. can quickly get back by hitting \fB\(ga\(ga\fR.
  474. .NH 2
  475. Moving around on the screen
  476. .PP
  477. Now try just moving the cursor around on the screen.
  478. If your terminal has arrow keys (4 or 5 keys with arrows
  479. going in each direction) try them and convince yourself
  480. that they work.
  481. If you don't have working arrow keys, you can always use
  482. .B h ,
  483. .B j ,
  484. .B k ,
  485. and
  486. .B l .
  487. Experienced users of
  488. .I vi
  489. prefer these keys to arrow keys,
  490. because they are usually right underneath their fingers.
  491. .PP
  492. Hit the \fB+\fR key.  Each time you do, notice that the cursor
  493. advances to the next line in the file, at the first non-white position
  494. on the line.  The \fB\-\fR key is like \fB+\fR but goes the other way.
  495. .PP
  496. These are very common keys for moving up and down lines in the file.
  497. Notice that if you go off the bottom or top with these keys then the
  498. screen will scroll down (and up if possible) to bring a line at a time
  499. into view.  The \s-2RETURN\s0 key has the same effect as the \fB+\fR
  500. key.
  501. .PP
  502. .I Vi
  503. also has commands to take you to the top, middle and bottom of the screen.
  504. \fBH\fR will take you to the top (home) line on the screen.
  505. Try preceding it with a
  506. number as in \fB3H\fR.
  507. This will take you to the third line on the screen.
  508. Many
  509. .I vi
  510. commands take preceding numbers and do interesting things with them.
  511. Try \fBM\fR,
  512. which takes you to the middle line on the screen,
  513. and \fBL\fR,
  514. which takes you to the last line on the screen.
  515. \fBL\fR also takes counts, thus
  516. \fB5L\fR will take you to the fifth line from the bottom.
  517. .NH 2
  518. Moving within a line
  519. .PP
  520. Now try picking a word on some line on the screen, not the
  521. first word on the line.
  522. move the cursor using \s-2RETURN\s0 and \fB\-\fR to be on the line where
  523. the word is.
  524. Try hitting the \fBw\fR key.  This will advance the cursor to the
  525. next word on the line.
  526. Try hitting the \fBb\fR key to back up words
  527. in the line.
  528. Also try the \fBe\fR key which advances you to the end of the current
  529. word rather than to the beginning of the next word.
  530. Also try \s-2SPACE\s0 (the space bar) which moves right one character
  531. and the \s-2BS\s0 (backspace or \fB^H\fR) key which moves left one character.
  532. The key \fBh\fR works as \fB^H\fR does and is useful if you don't have
  533. a \s-2BS\s0 key.
  534. (Also, as noted just above, \fBl\fR will move to the right.)
  535. .PP
  536. If the line had punctuation in it you may have noticed that
  537. that the \fBw\fR and \fBb\fR
  538. keys stopped at each group of punctuation.  You can also go back and
  539. forwards words without stopping at punctuation by using \fBW\fR and \fBB\fR
  540. rather than the lower case equivalents.  Think of these as bigger words.
  541. Try these on a few lines with punctuation to see how they differ from
  542. the lower case \fBw\fR and \fBb\fR.
  543. .PP
  544. The word keys wrap around the end of line,
  545. rather than stopping at the end.  Try moving to a word on a line below
  546. where you are by repeatedly hitting \fBw\fR.
  547. .NH 2
  548. Summary
  549. .IP
  550. .TS
  551. lw(.50i)b a.
  552. \fR\s-2SPACE\s0\fP    advance the cursor one position
  553. ^B    backwards to previous page
  554. ^D    scrolls down in the file
  555. ^E    exposes another line at the bottom
  556. ^F    forward to next page
  557. ^G    tell what is going on
  558. ^H    backspace the cursor
  559. ^N    next line, same column
  560. ^P    previous line, same column
  561. ^U    scrolls up in the file
  562. ^Y    exposes another line at the top
  563. +    next line, at the beginning
  564. \-    previous line, at the beginning
  565. /    scan for a following string forwards
  566. ?    scan backwards
  567. B    back a word, ignoring punctuation
  568. G    go to specified line, last default
  569. H    home screen line
  570. M    middle screen line
  571. L    last screen line
  572. W    forward a word, ignoring punctuation
  573. b    back a word
  574. e    end of current word
  575. n    scan for next instance of \fB/\fR or \fB?\fR pattern
  576. w    word after this word
  577. .TE
  578. .NH 2
  579. View
  580. .PP
  581. If you want to use the editor to look at a file,
  582. rather than to make changes,
  583. invoke it as
  584. .I view
  585. instead of
  586. .I vi .
  587. This will set the
  588. .I readonly
  589. option which will prevent you from
  590. accidently overwriting the file.
  591. .sp
  592. .NH 1
  593. Making simple changes
  594. .NH 2
  595. Inserting
  596. .PP
  597. One of the most useful commands is the
  598. \fBi\fR (insert) command.
  599. After you type \fBi\fR, everything you type until you hit \s-2ESC\s0
  600. is inserted into the file.
  601. Try this now; position yourself to some word in the file and try inserting
  602. text before this word.
  603. If you are on an dumb terminal it will seem, for a minute,
  604. that some of the characters in your line have been overwritten, but they will
  605. reappear when you hit \s-2ESC\s0.
  606. .PP
  607. Now try finding a word which can, but does not, end in an `s'.
  608. Position yourself at this word and type \fBe\fR (move to end of word), then
  609. \fBa\fR for append and then `s\s-2ESC\s0' to terminate the textual insert.
  610. This sequence of commands can be used to easily pluralize a word.
  611. .PP
  612. Try inserting and appending a few times to make sure you understand how
  613. this works; \fBi\fR placing text to the left of the cursor, \fBa\fR to
  614. the right.
  615. .PP
  616. It is often the case that you want to add new lines to the file you are
  617. editing, before or after some specific line in the file.  Find a line
  618. where this makes sense and then give the command \fBo\fR to create a
  619. new line after the line you are on, or the command \fBO\fR to create
  620. a new line before the line you are on.  After you create a new line in
  621. this way, text you type up to an \s-2ESC\s0 is inserted on the new line.
  622. .PP
  623. Many related editor commands
  624. are invoked by the same letter key and differ only in that one is given
  625. by a lower
  626. case key and the other is given by
  627. an upper case key.  In these cases, the
  628. upper case key often differs from the lower case key in its sense of
  629. direction, with
  630. the upper case key working backward and/or up, while the lower case
  631. key moves forward and/or down.
  632. .PP
  633. Whenever you are typing in text, you can give many lines of input or
  634. just a few characters.
  635. To type in more than one line of text,
  636. hit a \s-2RETURN\s0 at the middle of your input.  A new line will be created
  637. for text, and you can continue to type.  If you are on a slow
  638. and dumb terminal the editor may choose to wait to redraw the
  639. tail of the screen, and will let you type over the existing screen lines.
  640. This avoids the lengthy delay which would occur if the editor attempted
  641. to keep the tail of the screen always up to date.  The tail of the screen will
  642. be fixed up, and the missing lines will reappear, when you hit \s-2ESC\s0.
  643. .PP
  644. While you are inserting new text, you can use the characters you normally use
  645. at the system command level (usually \fB^H\fR or \fB#\fR) to backspace
  646. over the last
  647. character which you typed, and the character which you use to kill input lines
  648. (usually \fB@\fR, \fB^X\fR, or \fB^U\fR)
  649. to erase the input you have typed on the current line.\*(dg
  650. .FS
  651. \*(dg In fact, the character \fB^H\fR (backspace) always works to erase the
  652. last input character here, regardless of what your erase character is.
  653. .FE
  654. The character \fB^W\fR
  655. will erase a whole word and leave you after the space after the previous
  656. word; it is useful for quickly backing up in an insert.
  657. .PP
  658. Notice that when you backspace during an insertion the characters you
  659. backspace over are not erased; the cursor moves backwards, and the characters
  660. remain on the display.  This is often useful if you are planning to type
  661. in something similar.  In any case the characters disappear when when
  662. you hit \s-2ESC\s0; if you want to get rid of them immediately, hit an
  663. \s-2ESC\s0 and then \fBa\fR again.
  664. .PP
  665. Notice also that you can't erase characters which you didn't insert, and that
  666. you can't backspace around the end of a line.  If you need to back up
  667. to the previous line to make a correction, just hit \s-2ESC\s0 and move
  668. the cursor back to the previous line.  After making the correction you
  669. can return to where you were and use the insert or append command again.
  670. .sp .5
  671. .NH 2
  672. Making small corrections
  673. .PP
  674. You can make small corrections in existing text quite easily.
  675. Find a single character which is wrong or just pick any character.
  676. Use the arrow keys to find the character, or
  677. get near the character with the word motion keys and then either
  678. backspace (hit the \s-2BS\s0 key or \fB^H\fR or even just \fBh\fR) or 
  679. \s-2SPACE\s0 (using the space bar)
  680. until the cursor is on the character which is wrong.
  681. If the character is not needed then hit the \fBx\fP key; this deletes
  682. the character from the file.  It is analogous to the way you \fBx\fP
  683. out characters when you make mistakes on a typewriter (except it's not
  684. as messy).
  685. .PP
  686. If the character
  687. is incorrect, you can replace it with the correct character by giving
  688. the command \fBr\fR\fIc\fR,
  689. where \fIc\fR is replaced by the correct character.
  690. Finally if the character which is incorrect should be replaced
  691. by more than one character, give the command \fBs\fR which substitutes
  692. a string of characters, ending with \s-2ESC\s0, for it.
  693. If there are a small number of characters
  694. which are wrong you can precede \fBs\fR with a count of the number of
  695. characters to be replaced.  Counts are also useful with \fBx\fR to specify
  696. the number of characters to be deleted.
  697. .NH 2
  698. More corrections: operators
  699. .PP
  700. You already know almost enough to make changes at a higher level.
  701. All you need to know now is that the 
  702. .B d
  703. key acts as a delete operator.  Try the command
  704. .B dw
  705. to delete a word.
  706. Try hitting \fB.\fR a few times.  Notice that this repeats the effect
  707. of the \fBdw\fR.  The command \fB.\fR repeats the last command which
  708. made a change.  You can remember it by analogy with an ellipsis `\fB...\fR'.
  709. .PP
  710. Now try
  711. \fBdb\fR.
  712. This deletes a word backwards, namely the preceding word.
  713. Try 
  714. \fBd\fR\s-2SPACE\s0.  This deletes a single character, and is equivalent
  715. to the \fBx\fR command.
  716. .PP
  717. Another very useful operator is
  718. .B c
  719. or change.  The command 
  720. .B cw
  721. thus changes the text of a single word.
  722. You follow it by the replacement text ending with an \s-2ESC\s0.
  723. Find a word which you can change to another, and try this
  724. now.
  725. Notice that the end of the text to be changed was marked with the character
  726. `$' so that you can see this as you are typing in the new material.
  727. .sp .5
  728. .NH 2
  729. Operating on lines
  730. .PP
  731. It is often the case that you want to operate on lines.
  732. Find a line which you want to delete, and type 
  733. \fBdd\fR,
  734. the
  735. .B d
  736. operator twice.  This will delete the line.
  737. If you are on a dumb terminal, the editor may just erase the line on
  738. the screen, replacing it with a line with only an @ on it.  This line
  739. does not correspond to any line in your file, but only acts as a place
  740. holder.  It helps to avoid a lengthy redraw of the rest of the screen
  741. which would be necessary to close up the hole created by the deletion
  742. on a terminal without a delete line capability.
  743. .PP
  744. Try repeating the
  745. .B c
  746. operator twice; this will change a whole line, erasing its previous contents and
  747. replacing them with text you type up to an \s-2ESC\s0.\*(dg
  748. .FS
  749. \*(dg The command \fBS\fR is a convenient synonym for for \fBcc\fR, by
  750. analogy with \fBs\fR.  Think of \fBS\fR as a substitute on lines, while
  751. \fBs\fR is a substitute on characters.
  752. .FE
  753. .PP
  754. You can delete or change more than one line by preceding the
  755. .B dd
  756. or
  757. .B cc
  758. with a count, i.e. \fB5dd\fR deletes 5 lines.
  759. You can also give a command like \fBdL\fR to delete all the lines up to
  760. and including
  761. the last line on the screen, or \fBd3L\fR to delete through the third from
  762. the bottom line.  Try some commands like this now.*
  763. .FS
  764. * One subtle point here involves using the \fB/\fR search after a \fBd\fR.
  765. This will normally delete characters from the current position to the
  766. point of the match.  If what is desired is to delete whole lines
  767. including the two points, give the pattern as \fB/pat/+0\fR, a line address.
  768. .FE
  769. Notice that the editor lets you know when you change a large number of
  770. lines so that you can see the extent of the change.
  771. The editor will also always tell you when a change you make affects text which
  772. you cannot see.
  773. .NH 2
  774. Undoing
  775. .PP
  776. Now suppose that the last change which you made was incorrect;
  777. you could use the insert, delete and append commands to put the correct
  778. material back.  However, since it is often the case that we regret a
  779. change or make a change incorrectly, the editor provides a
  780. .B u
  781. (undo) command to reverse the last change which you made.
  782. Try this a few times, and give it twice in a row to notice that an
  783. .B u
  784. also undoes a
  785. .B u.
  786. .PP
  787. The undo command lets you reverse only a single change.  After you make
  788. a number of changes to a line, you may decide that you would rather have
  789. the original state of the line back.  The
  790. .B U
  791. command restores the current line to the state before you started changing
  792. it.
  793. .PP
  794. You can recover text which you delete, even if
  795. undo will not bring it back; see the section on recovering lost text
  796. below.
  797. .NH 2
  798. Summary
  799. .IP
  800. .TS
  801. lw(.50i)b a.
  802. \fR\s-2SPACE\s0\fP    advance the cursor one position
  803. ^H    backspace the cursor
  804. ^W    erase a word during an insert
  805. \fRerase\fP    your erase (usually ^H or #), erases a character during an insert
  806. \fRkill\fP    your kill (usually @, ^X, or ^U), kills the insert on this line
  807. \&\fB.\fP    repeats the changing command
  808. O    opens and inputs new lines, above the current
  809. U    undoes the changes you made to the current line
  810. a    appends text after the cursor
  811. c    changes the object you specify to the following text
  812. d    deletes the object you specify
  813. i    inserts text before the cursor
  814. o    opens and inputs new lines, below the current
  815. u    undoes the last change
  816. .TE
  817. .NH 1
  818. Moving about; rearranging and duplicating text
  819. .NH 2
  820. Low level character motions
  821. .PP
  822. Now move the cursor to a line where there is a punctuation or a bracketing
  823. character such as a parenthesis or a comma or period.  Try the command
  824. \fBf\fR\fIx\fR where \fIx\fR is this character.  This command finds
  825. the next \fIx\fR character to the right of the cursor in the current
  826. line.  Try then hitting a \fB;\fR, which finds the next instance of the
  827. same character.  By using the \fBf\fR command and then a sequence of
  828. \fB;\fR's you can often
  829. get to a particular place in a line much faster than with a sequence
  830. of word motions or \s-2SPACE\s0s.
  831. There is also a \fBF\fR command, which is like \fBf\fR, but searches 
  832. backward.  The \fB;\fR command repeats \fBF\fR also.
  833. .PP
  834. When you are operating on the text in a line it is often desirable to
  835. deal with the characters up to, but not including, the first instance of
  836. a character.  Try \fBdf\fR\fIx\fR for some \fIx\fR now and
  837. notice that the \fIx\fR character is deleted.  Undo this with \fBu\fR
  838. and then try \fBdt\fR\fIx\fR;  the \fBt\fR here stands for to, i.e.
  839. delete up to the next \fIx\fR, but not the \fIx\fR.  The command \fBT\fR
  840. is the reverse of \fBt\fR.
  841. .PP
  842. When working with the text of a single line, an \fB\(ua\fR moves the
  843. cursor to the first non-white position on the line, and a
  844. \fB$\fR moves it to the end of the line.  Thus \fB$a\fR will append new
  845. text at the end of the current line.
  846. .PP
  847. Your file may have tab (\fB^I\fR) characters in it.  These
  848. characters are represented as a number of spaces expanding to a tab stop,
  849. where tab stops are every 8 positions.*
  850. .FS
  851. * This is settable by a command of the form \fB:se ts=\fR\fIx\fR\s-2CR\s0,
  852. where \fIx\fR is 4 to set tabstops every four columns.  This has
  853. effect on the screen representation within the editor.
  854. .FE
  855. When the cursor is at a tab, it sits on the last of the several spaces
  856. which represent that tab.  Try moving the cursor back and forth over
  857. tabs so you understand how this works.
  858. .PP
  859. On rare occasions, your file may have nonprinting characters in it. 
  860. These characters are displayed in the same way they are represented in
  861. this document, that is with a two character code, the first character
  862. of which is `^'.  On the screen non-printing characters resemble a `^'
  863. character adjacent to another, but spacing or backspacing over the character
  864. will reveal that the two characters are, like the spaces representing
  865. a tab character, a single character.
  866. .PP
  867. The editor sometimes discards control characters,
  868. depending on the character and the setting of the
  869. .I beautify
  870. option,
  871. if you attempt to insert them in your file.
  872. You can get a control character in the file by beginning
  873. an insert and then typing a \fB^V\fR before the control
  874. character.  The
  875. \fB^V\fR quotes the following character, causing it to be
  876. inserted directly into the file.
  877. .PP
  878. .NH 2
  879. Higher level text objects
  880. .PP
  881. In working with a document it is often advantageous to work in terms
  882. of sentences, paragraphs, and sections.  The operations \fB(\fR and \fB)\fR
  883. move to the beginning of the previous and next sentences respectively.
  884. Thus the command \fBd)\fR will delete the rest of the current sentence;
  885. likewise \fBd(\fR will delete the previous sentence if you are at the
  886. beginning of the current sentence, or the current sentence up to where
  887. you are if you are not at the beginning of the current sentence.
  888. .PP
  889. A sentence is defined to end at a `.', `!' or `?' which is followed by
  890. either the end of a line, or by two spaces.  Any number of closing `)',
  891. `]', `"' and `\(aa' characters may appear after the `.', `!' or `?' before
  892. the spaces or end of line.
  893. .PP
  894. The operations \fB{\fR and \fB}\fR move over paragraphs and the operations
  895. \fB[[\fR and \fB]]\fR move over sections.\*(dg
  896. .FS
  897. \*(dg The \fB[[\fR and \fB]]\fR operations
  898. require the operation character to be doubled because they can move the
  899. cursor far from where it currently is.  While it is easy to get back
  900. with the command \fB\(ga\(ga\fP,
  901. these commands would still be frustrating
  902. if they were easy to hit accidentally.
  903. .FE
  904. .PP
  905. A paragraph begins after each empty line, and also
  906. at each of a set of paragraph macros, specified by the pairs of characters
  907. in the definition of the string valued option \fIparagraphs\fR.
  908. The default setting for this option defines the paragraph macros of the
  909. \fI\-ms\fR and \fI\-mm\fR macro packages, i.e. the `.IP', `.LP', `.PP'
  910. and `.QP', `.P' and `.LI' macros.\*(dd
  911. .FS
  912. \*(dd You can easily change or extend this set of macros by assigning a
  913. different string to the \fIparagraphs\fR option in your EXINIT.
  914. See section 6.2 for details.
  915. The `.bp' directive is also considered to start a paragraph.
  916. .FE
  917. Each paragraph boundary is also a sentence boundary.  The sentence
  918. and paragraph commands can
  919. be given counts to operate over groups of sentences and paragraphs.
  920. .PP
  921. Sections in the editor begin after each macro in the \fIsections\fR option,
  922. normally `.NH', `.SH', `.H' and `.HU', and each line with a formfeed \fB^L\fR
  923. in the first column.
  924. Section boundaries are always line and paragraph boundaries also.
  925. .PP
  926. Try experimenting with the sentence and paragraph commands until you are
  927. sure how they work.  If you have a large document, try looking through
  928. it using the section commands.
  929. The section commands interpret a preceding count as a different window size in
  930. which to redraw the screen at the new location, and this window size
  931. is the base size for newly drawn windows until another size is specified.
  932. This is very useful
  933. if you are on a slow terminal and are looking for a particular section. 
  934. You can give the first section command a small count to then see each successive
  935. section heading in a small window.
  936. .NH 2
  937. Rearranging and duplicating text
  938. .PP
  939. The editor has a single unnamed buffer where the last deleted or
  940. changed away text is saved, and a set of named buffers \fBa\fR\-\fBz\fR
  941. which you can use to save copies of text and to move text around in
  942. your file and between files.
  943. .PP
  944. The operator
  945. .B y
  946. yanks a copy of the object which follows into the unnamed buffer.
  947. If preceded by a buffer name, \fB"\fR\fIx\fR\|\fBy\fR, where
  948. \fIx\fR here is replaced by a letter \fBa\-z\fR, it places the text in the named
  949. buffer.  The text can then be put back in the file with the commands
  950. .B p
  951. and
  952. .B P;
  953. \fBp\fR puts the text after or below the cursor, while \fBP\fR puts the text
  954. before or above the cursor.
  955. .PP
  956. If the text which you
  957. yank forms a part of a line, or is an object such as a sentence which
  958. partially spans more than one line, then when you put the text back,
  959. it will be placed after the cursor (or before if you
  960. use \fBP\fR).  If the yanked text forms whole lines, they will be put
  961. back as whole lines, without changing the current line.  In this case,
  962. the put acts much like a \fBo\fR or \fBO\fR command.
  963. .PP
  964. Try the command \fBYP\fR.  This makes a copy of the current line and
  965. leaves you on this copy, which is placed before the current line.
  966. The command \fBY\fR is a convenient abbreviation for \fByy\fR.
  967. The command \fBYp\fR will also make a copy of the current line, and place
  968. it after the current line.  You can give \fBY\fR a count of lines to
  969. yank, and thus duplicate several lines; try \fB3YP\fR.
  970. .PP
  971. To move text within the buffer, you need to delete it in one place, and
  972. put it back in another.  You can precede a delete operation by the
  973. name of a buffer in which the text is to be stored as in \fB"a5dd\fR
  974. deleting 5 lines into the named buffer \fIa\fR.  You can then move the
  975. cursor to the eventual resting place of the these lines and do a \fB"ap\fR
  976. or \fB"aP\fR to put them back.
  977. In fact, you can switch and edit another file before you put the lines
  978. back, by giving a command of the form \fB:e \fR\fIname\fR\s-2CR\s0 where
  979. \fIname\fR is the name of the other file you want to edit.  You will
  980. have to write back the contents of the current editor buffer (or discard
  981. them) if you have made changes before the editor will let you switch
  982. to the other file.
  983. An ordinary delete command saves the text in the unnamed buffer,
  984. so that an ordinary put can move it elsewhere.
  985. However, the unnamed buffer is lost when you change files,
  986. so to move text from one file to another you should use an unnamed buffer.
  987. .NH 2
  988. Summary.
  989. .IP
  990. .TS
  991. lw(.50i)b a.
  992. \(ua    first non-white on line
  993. $    end of line
  994. )    forward sentence
  995. }    forward paragraph
  996. ]]    forward section
  997. (    backward sentence
  998. {    backward paragraph
  999. [[    backward section
  1000. f\fIx\fR    find \fIx\fR forward in line
  1001. p    put text back, after cursor or below current line
  1002. y    yank operator, for copies and moves
  1003. t\fIx\fR    up to \fIx\fR forward, for operators
  1004. F\fIx\fR    f backward in line
  1005. P    put text back, before cursor or above current line
  1006. T\fIx\fR    t backward in line
  1007. .TE
  1008. .ne 1i
  1009. .NH 1
  1010. High level commands
  1011. .NH 2
  1012. Writing, quitting, editing new files
  1013. .PP
  1014. So far we have seen how to enter
  1015. .I vi
  1016. and to write out our file using either
  1017. \fBZZ\fR or \fB:w\fR\s-2CR\s0. The first exits from
  1018. the editor,
  1019. (writing if changes were made),
  1020. the second writes and stays in the editor.
  1021. .PP
  1022. If you have changed the editor's copy of the file but do not wish to
  1023. save your changes, either because you messed up the file or decided that the
  1024. changes are not an improvement to the file, then you can give the command
  1025. \fB:q!\fR\s-2CR\s0 to quit from the editor without writing the changes.
  1026. You can also reedit the same file (starting over) by giving the command
  1027. \fB:e!\fR\s-2CR\s0.  These commands should be used only rarely, and with
  1028. caution, as it is not possible to recover the changes you have made after
  1029. you discard them in this manner.
  1030. .PP
  1031. You can edit a different file without leaving the editor by giving the
  1032. command \fB:e\fR\ \fIname\fR\s-2CR\s0.  If you have not written out
  1033. your file before you try to do this, then the editor will tell you this,
  1034. and delay editing the other file.  You can then give the command
  1035. \fB:w\fR\s-2CR\s0 to save your work and then the \fB:e\fR\ \fIname\fR\s-2CR\s0
  1036. command again, or carefully give the command \fB:e!\fR\ \fIname\fR\s-2CR\s0,
  1037. which edits the other file discarding the changes you have made to the
  1038. current file.
  1039. To have the editor automatically save changes,
  1040. include
  1041. .I "set autowrite"
  1042. in your EXINIT,
  1043. and use \fB:n\fP instead of \fB:e\fP.
  1044. .NH 2
  1045. Escaping to a shell
  1046. .PP
  1047. You can get to a shell to execute a single command by giving a
  1048. .I vi
  1049. command of the form \fB:!\fIcmd\fR\s-2CR\s0.
  1050. The system will run the single command
  1051. .I cmd
  1052. and when the command finishes, the editor will ask you to hit a \s-2RETURN\s0
  1053. to continue.  When you have finished looking at the output on the screen,
  1054. you should hit \s-2RETURN\s0 and the editor will clear the screen and
  1055. redraw it.  You can then continue editing.
  1056. You can also give another \fB:\fR command when it asks you for a \s-2RETURN\s0;
  1057. in this case the screen will not be redrawn.
  1058. .PP
  1059. If you wish to execute more than one command in the shell, then you can
  1060. give the command \fB:sh\fR\s-2CR\s0.
  1061. This will give you a new shell, and when you finish with the shell, ending
  1062. it by typing a \fB^D\fR, the editor will clear the screen and continue.
  1063. .PP
  1064. On systems which support it, \fB^Z\fP will suspend the editor
  1065. and return to the (top level) shell.
  1066. When the editor is resumed, the screen will be redrawn.
  1067. .NH 2
  1068. Marking and returning
  1069. .PP
  1070. The command \fB\(ga\(ga\fR returned to the previous place
  1071. after a motion of the cursor by a command such as \fB/\fR, \fB?\fR or
  1072. \fBG\fR.  You can also mark lines in the file with single letter tags
  1073. and return to these marks later by naming the tags.  Try marking the
  1074. current line with the command \fBm\fR\fIx\fR, where you should pick some
  1075. letter for \fIx\fR, say `a'.  Then move the cursor to a different line
  1076. (any way you like) and hit \fB\(gaa\fR.  The cursor will return to the
  1077. place which you marked.
  1078. Marks last only until you edit another file.
  1079. .PP
  1080. When using operators such as
  1081. .B d
  1082. and referring to marked lines, it is often desirable to delete whole lines
  1083. rather than deleting to the exact position in the line marked by \fBm\fR.
  1084. In this case you can use the form \fB\(aa\fR\fIx\fR rather than
  1085. \fB\(ga\fR\fIx\fR.  Used without an operator, \fB\(aa\fR\fIx\fR will move to
  1086. the first non-white character of the marked line; similarly \fB\(aa\(aa\fR
  1087. moves to the first non-white character of the line containing the previous
  1088. context mark \fB\(ga\(ga\fR.
  1089. .NH 2
  1090. Adjusting the screen
  1091. .PP
  1092. If the screen image is messed up because of a transmission error to your
  1093. terminal, or because some program other than the editor wrote output
  1094. to your terminal, you can hit a \fB^L\fR, the \s-2ASCII\s0 form-feed
  1095. character, to cause the screen to be refreshed.
  1096. .PP
  1097. On a dumb terminal, if there are @ lines in the middle of the screen
  1098. as a result of line deletion, you may get rid of these lines by typing
  1099. \fB^R\fR to cause the editor to retype the screen, closing up these holes.
  1100. .PP
  1101. Finally, if you wish to place a certain line on the screen at the top
  1102. middle or bottom of the screen, you can position the cursor to that line,
  1103. and then give a \fBz\fR command.
  1104. You should follow the \fBz\fR command with a \s-2RETURN\s0 if you want
  1105. the line to appear at the top of the window, a \fB.\fR if you want it
  1106. at the center, or a \fB\-\fR if you want it at the bottom.
  1107. .NH 1
  1108. Special topics
  1109. .NH 2
  1110. Editing on slow terminals
  1111. .PP
  1112. When you are on a slow terminal, it is important to limit the amount
  1113. of output which is generated to your screen so that you will not suffer
  1114. long delays, waiting for the screen to be refreshed.  We have already
  1115. pointed out how the editor optimizes the updating of the screen during
  1116. insertions on dumb terminals to limit the delays, and how the editor erases
  1117. lines to @ when they are deleted on dumb terminals.
  1118. .PP
  1119. The use of the slow terminal insertion mode is controlled by the
  1120. .I slowopen
  1121. option.  You can force the editor to use this mode even on faster terminals
  1122. by giving the command \fB:se slow\fR\s-2CR\s0.  If your system is sluggish
  1123. this helps lessen the amount of output coming to your terminal.
  1124. You can disable this option by \fB:se noslow\fR\s-2CR\s0.
  1125. .PP
  1126. The editor can simulate an intelligent terminal on a dumb one.  Try
  1127. giving the command \fB:se redraw\fR\s-2CR\s0.  This simulation generates
  1128. a great deal of output and is generally tolerable only on lightly loaded
  1129. systems and fast terminals.  You can disable this by giving the command
  1130.  \fB:se noredraw\fR\s-2CR\s0.
  1131. .PP
  1132. The editor also makes editing more pleasant at low speed by starting
  1133. editing in a small window, and letting the window expand as you edit.
  1134. This works particularly well on intelligent terminals.  The editor can
  1135. expand the window easily when you insert in the middle of the screen
  1136. on these terminals.  If possible, try the editor on an intelligent terminal
  1137. to see how this works.
  1138. .PP
  1139. You can control the size of the window which is redrawn each time the
  1140. screen is cleared by giving window sizes as argument to the commands
  1141. which cause large screen motions:
  1142. .DS
  1143. .B ":  /  ?  [[  ]]  \(ga  \(aa"
  1144. .DE
  1145. Thus if you are searching for a particular instance of a common string
  1146. in a file you can precede the first search command by a small number,
  1147. say 3, and the editor will draw three line windows around each instance
  1148. of the string which it locates.
  1149. .PP
  1150. You can easily expand or contract the window, placing the current line
  1151. as you choose, by giving a number on a \fBz\fR command, after the \fBz\fR
  1152. and before the following \s-2RETURN\s0, \fB.\fR or \fB\-\fR.  Thus the
  1153. command \fBz5.\fR redraws the screen with the current line in the center
  1154. of a five line window.\*(dg
  1155. .FS
  1156. \*(dg Note that the command \fB5z.\fR has an entirely different effect,
  1157. placing line 5 in the center of a new window.
  1158. .FE
  1159. .PP
  1160. If the editor is redrawing or otherwise updating large portions of the
  1161. display, you can interrupt this updating by hitting a \s-2DEL\s0 or \s-2RUB\s0
  1162. as usual.  If you do this you may partially confuse the editor about
  1163. what is displayed on the screen.  You can still edit the text on
  1164. the screen if you wish; clear up the confusion
  1165. by hitting a \fB^L\fR; or move or search again, ignoring the
  1166. current state of the display.
  1167. .PP
  1168. See section 7.8 on \fIopen\fR mode for another way to use the
  1169. .I vi
  1170. command set on slow terminals.
  1171. .NH 2
  1172. Options, set, and editor startup files
  1173. .PP
  1174. The editor has a set of options, some of which have been mentioned above.
  1175. The most useful options are given in the following table.
  1176. .PP
  1177. The options are of three kinds:  numeric options, string options, and
  1178. toggle options.  You can set numeric and string options by a statement
  1179. of the form
  1180. .DS
  1181. \fBset\fR \fIopt\fR\fB=\fR\fIval\fR
  1182. .DE
  1183. and toggle options can be set or unset by statements of one of the forms
  1184. .DS
  1185. \fBset\fR \fIopt\fR
  1186. \fBset\fR \fBno\fR\fIopt\fR
  1187. .DE
  1188. .KF
  1189. .TS
  1190. lb lb lb lb
  1191. l l l a.
  1192. Name    Default    Description
  1193. _
  1194. autoindent    noai    Supply indentation automatically
  1195. autowrite    noaw    Automatic write before \fB:n\fR, \fB:ta\fR, \fB^\(ua\fR, \fB!\fR
  1196. ignorecase    noic    Ignore case in searching
  1197. lisp    nolisp    \fB( { ) }\fR commands deal with S-expressions
  1198. list    nolist    Tabs print as ^I; end of lines marked with $
  1199. magic    nomagic    The characters . [ and * are special in scans
  1200. number    nonu    Lines are displayed prefixed with line numbers
  1201. paragraphs    para=IPLPPPQPbpP LI    Macro names which start paragraphs
  1202. redraw    nore    Simulate a smart terminal on a dumb one
  1203. sections    sect=NHSHH HU    Macro names which start new sections
  1204. shiftwidth    sw=8    Shift distance for <, > and input \fB^D\fP and \fB^T\fR
  1205. showmatch    nosm    Show matching \fB(\fP or \fB{\fP as \fB)\fP or \fB}\fR is typed
  1206. slowopen    slow    Postpone display updates during inserts
  1207. term    dumb    The kind of terminal you are using.
  1208. .TE
  1209. .KE
  1210. These statements can be placed in your EXINIT in your environment,
  1211. or given while you are running
  1212. .I vi
  1213. by preceding them with a \fB:\fR and following them with a \s-2CR\s0.
  1214. .PP
  1215. You can get a list of all options which you have changed by the
  1216. command \fB:set\fR\s-2CR\s0, or the value of a single option by the
  1217. command \fB:set\fR \fIopt\fR\fB?\fR\s-2CR\s0.
  1218. A list of all possible options and their values is generated by
  1219. \fB:set all\fP\s-2CR\s0.
  1220. Set can be abbreviated \fBse\fP.
  1221. Multiple options can be placed on one line, e.g.
  1222. \fB:se ai aw nu\fP\s-2CR\s0.
  1223. .PP
  1224. Options set by the \fBset\fP command only last
  1225. while you stay in the editor.
  1226. It is common to want to have certain options set whenever you
  1227. use the editor.
  1228. This can be accomplished by creating a list of \fIex\fP commands\*(dg
  1229. .FS
  1230. \*(dg
  1231. All commands which start with
  1232. .B :
  1233. are \fIex\fP commands.
  1234. .FE
  1235. which are to be run every time you start up \fIex\fP, \fIedit\fP,
  1236. or \fIvi\fP.
  1237. A typical list includes a \fBset\fP command, and possibly a few
  1238. \fBmap\fP commands.
  1239. Since it is advisable to get these commands on one line, they can
  1240. be separated with the | character, for example:
  1241. .DS
  1242. \fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x
  1243. .DE
  1244. which sets the options \fIautoindent\fP, \fIautowrite\fP, \fIterse\fP,
  1245. (the
  1246. .B set
  1247. command),
  1248. makes @ delete a line,
  1249. (the first
  1250. .B map ),
  1251. and makes # delete a character,
  1252. (the second
  1253. .B map ).
  1254. (See section 6.9 for a description of the \fBmap\fP command)
  1255. This string should be placed in the variable EXINIT in your environment.
  1256. If you use the shell \fIcsh\fP,
  1257. put this line in the file
  1258. .I .login
  1259. in your home directory:
  1260. .DS
  1261. setenv EXINIT \(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aa
  1262. .DE
  1263. If you use the standard shell \fIsh\fP,
  1264. put these lines in the file
  1265. .I .profile
  1266. in your home directory:
  1267. .DS
  1268. EXINIT=\(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aa
  1269. export EXINIT
  1270. .DE
  1271. Of course, the particulars of the line would depend on which options
  1272. you wanted to set.
  1273. .NH 2
  1274. Recovering lost lines
  1275. .PP
  1276. You might have a serious problem if you delete a number of lines and then
  1277. regret that they were deleted.  Despair not, the editor saves the last
  1278. 9 deleted blocks of text in a set of numbered registers 1\-9.
  1279. You can get the \fIn\fR'th previous deleted text back in your file by
  1280. the command
  1281. "\fR\fIn\fR\|\fBp\fR.
  1282. The "\fR here says that a buffer name is to follow,
  1283. \fIn\fR is the number of the buffer you wish to try
  1284. (use the number 1 for now),
  1285. and
  1286. .B p
  1287. is the put command, which puts text in the buffer after the cursor.
  1288. If this doesn't bring back the text you wanted, hit
  1289. .B u
  1290. to undo this and then
  1291. \fB\&.\fR
  1292. (period)
  1293. to repeat the put command.
  1294. In general the
  1295. \fB\&.\fR
  1296. command will repeat the last change you made.
  1297. As a special case, when the last command refers to a numbered text buffer,
  1298. the \fB.\fR command increments the number of the buffer before repeating
  1299. the command.  Thus a sequence of the form
  1300. .DS
  1301. \fB"1pu.u.u.\fR
  1302. .DE
  1303. will, if repeated long enough, show you all the deleted text which has
  1304. been saved for you.
  1305. You can omit the
  1306. .B u
  1307. commands here to gather up all this text in the buffer, or stop after any
  1308. \fB\&.\fR command to keep just the then recovered text.
  1309. The command
  1310. .B P
  1311. can also be used rather than
  1312. .B p
  1313. to put the recovered text before rather than after the cursor.
  1314. .NH 2
  1315. Recovering lost files
  1316. .PP
  1317. If the system crashes, you can recover the work you were doing
  1318. to within a few changes.  You will normally receive mail when you next
  1319. login giving you the name of the file which has been saved for you. 
  1320. You should then change to the directory where you were when the system
  1321. crashed and give a command of the form:
  1322. .DS
  1323. % \fBvi \-r\fR \fIname\fR
  1324. .DE
  1325. replacing \fIname\fR with the name of the file which you were editing.
  1326. This will recover your work to a point near where you left off.\*(dg
  1327. .FS
  1328. \*(dg In rare cases, some of the lines of the file may be lost.  The
  1329. editor will give you the numbers of these lines and the text of the lines
  1330. will be replaced by the string `LOST'.  These lines will almost always
  1331. be among the last few which you changed.  You can either choose to discard
  1332. the changes which you made (if they are easy to remake) or to replace
  1333. the few lost lines by hand.
  1334. .FE
  1335. .PP
  1336. You can get a listing of the files which are saved for you by giving
  1337. the command:
  1338. .DS
  1339. % \fBvi \-r\fR
  1340. .DE
  1341. If there is more than one instance of a particular file saved, the editor
  1342. gives you the newest instance each time you recover it.  You can thus
  1343. get an older saved copy back by first recovering the newer copies.
  1344. .PP
  1345. For this feature to work,
  1346. .I vi
  1347. must be correctly installed by a super user on your system,
  1348. and the
  1349. .I mail
  1350. program must exist to receive mail.
  1351. The invocation ``\fIvi -r\fP'' will not always list all saved files,
  1352. but they can be recovered even if they are not listed.
  1353. .NH 2
  1354. Continuous text input
  1355. .PP
  1356. When you are typing in large amounts of text it is convenient to have
  1357. lines broken near the right margin automatically.  You can cause this
  1358. to happen by giving the command
  1359. \fB:se wm=10\fR\s-2CR\s0.
  1360. This causes all lines to be broken at a space at least 10 columns
  1361. from the right hand edge of the screen.
  1362. .PP
  1363. If the editor breaks an input line and you wish to put it back together
  1364. you can tell it to join the lines with \fBJ\fR.  You can give \fBJ\fR
  1365. a count of the number of lines to be joined as in \fB3J\fR to join 3
  1366. lines.  The editor supplies white space, if appropriate,
  1367. at the juncture of the joined
  1368. lines, and leaves the cursor at this white space.
  1369. You can kill the white space with \fBx\fR if you don't want it.
  1370. .NH 2
  1371. Features for editing programs
  1372. .PP
  1373. The editor has a number of commands for editing programs.
  1374. The thing that most distinguishes editing of programs from editing of text
  1375. is the desirability of maintaining an indented structure to the body of
  1376. the program.  The editor has a
  1377. .I autoindent
  1378. facility for helping you generate correctly indented programs.
  1379. .PP
  1380. To enable this facility you can give the command \fB:se ai\fR\s-2CR\s0.
  1381. Now try opening a new line with \fBo\fR and type some characters on the
  1382. line after a few tabs.  If you now start another line, notice that the
  1383. editor supplies white space at the beginning of the line to line it up
  1384. with the previous line.  You cannot backspace over this indentation,
  1385. but you can use \fB^D\fR key to backtab over the supplied indentation.
  1386. .PP
  1387. Each time you type \fB^D\fR you back up one position, normally to an
  1388. 8 column boundary.  This amount is settable; the editor has an option
  1389. called
  1390. .I shiftwidth
  1391. which you can set to change this value.
  1392. Try giving the command \fB:se sw=4\fR\s-2CR\s0
  1393. and then experimenting with autoindent again.
  1394. .PP
  1395. For shifting lines in the program left and right, there are operators
  1396. .B <
  1397. and
  1398. .B >.
  1399. These shift the lines you specify right or left by one
  1400. .I shiftwidth.
  1401. Try
  1402. .B <<
  1403. and
  1404. .B >>
  1405. which shift one line left or right, and
  1406. .B <L
  1407. and
  1408. .B >L
  1409. shifting the rest of the display left and right.
  1410. .PP
  1411. If you have a complicated expression and wish to see how the parentheses
  1412. match, put the cursor at a left or right parenthesis and hit \fB%\fR.
  1413. This will show you the matching parenthesis.
  1414. This works also for braces { and }, and brackets [ and ].
  1415. .PP
  1416. If you are editing C programs, you can use the \fB[[\fR and \fB]]\fR keys
  1417. to advance or retreat to a line starting with a \fB{\fR, i.e. a function
  1418. declaration at a time.  When \fB]]\fR is used with an operator it stops
  1419. after a line which starts with \fB}\fR; this is sometimes useful with
  1420. \fBy]]\fR.
  1421. .NH 2
  1422. Filtering portions of the buffer
  1423. .PP
  1424. You can run system commands over portions of the buffer using the operator
  1425. \fB!\fR.
  1426. You can use this to sort lines in the buffer, or to reformat portions
  1427. of the buffer with a pretty-printer.
  1428. Try typing in a list of random words, one per line and ending them
  1429. with a blank line.  Back up to the beginning of the list, and then give
  1430. the command \fB!}sort\fR\s-2CR\s0.  This says to sort the next paragraph
  1431. of material, and the blank line ends a paragraph.
  1432. .NH 2
  1433. Commands for editing \s-2LISP\s0
  1434. .PP
  1435. If you are editing a \s-2LISP\s0 program you should set the option
  1436. .I lisp
  1437. by doing
  1438. \fB:se\ lisp\fR\s-2CR\s0.
  1439. This changes the \fB(\fR and \fB)\fR commands to move backward and forward
  1440. over s-expressions.
  1441. The \fB{\fR and \fB}\fR commands are like \fB(\fR and \fB)\fR but don't
  1442. stop at atoms.  These can be used to skip to the next list, or through
  1443. a comment quickly.
  1444. .PP
  1445. The
  1446. .I autoindent
  1447. option works differently for \s-2LISP\s0, supplying indent to align at
  1448. the first argument to the last open list.  If there is no such argument
  1449. then the indent is two spaces more than the last level.
  1450. .PP
  1451. There is another option which is useful for typing in \s-2LISP\s0, the
  1452. .I showmatch
  1453. option.
  1454. Try setting it with
  1455. \fB:se sm\fR\s-2CR\s0
  1456. and then try typing a `(' some words and then a `)'.  Notice that the
  1457. cursor shows the position of the `(' which matches the `)' briefly. 
  1458. This happens only if the matching `(' is on the screen, and the cursor
  1459. stays there for at most one second.
  1460. .PP
  1461. The editor also has an operator to realign existing lines as though they
  1462. had been typed in with
  1463. .I lisp
  1464. and
  1465. .I autoindent
  1466. set.  This is the \fB=\fR operator.
  1467. Try the command \fB=%\fR at the beginning of a function.  This will realign
  1468. all the lines of the function declaration.
  1469. .PP
  1470. When you are editing \s-2LISP\s0,, the \fB[[\fR and \fR]]\fR advance
  1471. and retreat to lines beginning with a \fB(\fR, and are useful for dealing
  1472. with entire function definitions.
  1473. .NH 2
  1474. Macros
  1475. .PP
  1476. .I Vi
  1477. has a parameterless macro facility, which lets you set it up so that
  1478. when you hit a single keystroke, the editor will act as though
  1479. you had hit some longer sequence of keys.  You can set this up if
  1480. you find yourself typing the same sequence of commands repeatedly.
  1481. .PP
  1482. Briefly, there are two flavors of macros:
  1483. .IP a)
  1484. Ones where you put the macro body in a buffer register, say \fIx\fR.
  1485. You can then type \fB@x\fR to invoke the macro.  The \fB@\fR may be followed
  1486. by another \fB@\fR to repeat the last macro.
  1487. .IP b)
  1488. You can use the
  1489. .I map
  1490. command from
  1491. .I vi
  1492. (typically in your
  1493. .I EXINIT )
  1494. with a command of the form:
  1495. .DS
  1496. :map \fIlhs\fR \fIrhs\fR\s-2CR
  1497. .DE
  1498. mapping
  1499. .I lhs
  1500. into
  1501. .I rhs.
  1502. There are restrictions:
  1503. .I lhs
  1504. should be one keystroke (either 1 character or one function key)
  1505. since it must be entered within one second
  1506. (unless
  1507. .I notimeout
  1508. is set, in which case you can type it as slowly as you wish,
  1509. and
  1510. .I vi
  1511. will wait for you to finish it before it echoes anything).
  1512. The
  1513. .I lhs
  1514. can be no longer than 10 characters, the
  1515. .I rhs
  1516. no longer than 100.
  1517. To get a space, tab or newline into
  1518. .I lhs
  1519. or
  1520. .I rhs
  1521. you should escape them with a \fB^V\fR.
  1522. (It may be necessary to double the \fB^V\fR if the map
  1523. command is given inside
  1524. .I vi,
  1525. rather than in
  1526. .I ex.)
  1527. Spaces and tabs inside the
  1528. .I rhs
  1529. need not be escaped.
  1530. .PP
  1531. Thus to make the \fBq\fR key write and exit the editor, you can give
  1532. the command
  1533. .DS
  1534. :map q :wq\fB^V^V\fP\s-2CR CR\s0
  1535. .DE
  1536. which means that whenever you type \fBq\fR, it will be as though you
  1537. had typed the four characters \fB:wq\fR\s-2CR\s0.
  1538. A \fB^V\fR's is needed because without it the \s-2CR\s0 would end the
  1539. \fB:\fR command, rather than becoming part of the
  1540. .I map
  1541. definition.
  1542. There are two
  1543. .B ^V 's
  1544. because from within
  1545. .I vi ,
  1546. two
  1547. .B ^V 's
  1548. must be typed to get one.
  1549. The first \s-2CR\s0 is part of the
  1550. .I rhs ,
  1551. the second terminates the : command.
  1552. .PP
  1553. Macros can be deleted with
  1554. .DS
  1555. unmap lhs
  1556. .DE
  1557. .PP
  1558. If the
  1559. .I lhs
  1560. of a macro is ``#0'' through ``#9'', this maps the particular function key
  1561. instead of the 2 character ``#'' sequence.  So that terminals without
  1562. function keys can access such definitions, the form ``#x'' will mean function
  1563. key
  1564. .I x
  1565. on all terminals (and need not be typed within one second.)
  1566. The character ``#'' can be changed by using a macro in the usual way:
  1567. .DS
  1568. :map \fB^V^V^I\fP #
  1569. .DE
  1570. to use tab, for example.  (This won't affect the
  1571. .I map
  1572. command, which still uses
  1573. .B #,
  1574. but just the invocation from visual mode.
  1575. .PP
  1576. The undo command reverses an entire macro call as a unit,
  1577. if it made any changes.
  1578. .PP
  1579. Placing a `!' after the word
  1580. .B map
  1581. causes the mapping to apply
  1582. to input mode, rather than command mode.
  1583. Thus, to arrange for \fB^T\fP to be the same as 4 spaces in input mode,
  1584. you can type:
  1585. .DS
  1586. :map \fB^T\fP \fB^V\fP\o'b/'\o'b/'\o'b/'\o'b/'
  1587. .DE
  1588. where
  1589. .B \o'b/'
  1590. is a blank.
  1591. The \fB^V\fP is necessary to prevent the blanks from being taken as
  1592. white space between the
  1593. .I lhs
  1594. and
  1595. .I rhs .
  1596. .NH
  1597. Word Abbreviations
  1598. .PP
  1599. A feature similar to macros in input mode is word abbreviation.
  1600. This allows you to type a short word and have it expanded into
  1601. a longer word or words.
  1602. The commands are
  1603. .B :abbreviate
  1604. and
  1605. .B :unabbreviate
  1606. (\fB:ab\fP
  1607. and
  1608. .B :una )
  1609. and have the same syntax as
  1610. .B :map .
  1611. For example:
  1612. .DS
  1613. :ab eecs Electrical Engineering and Computer Sciences
  1614. .DE
  1615. causes the word `eecs' to always be changed into the
  1616. phrase `Electrical Engineering and Computer Sciences'.
  1617. Word abbreviation is different from macros in that
  1618. only whole words are affected.
  1619. If `eecs' were typed as part of a larger word, it would
  1620. be left alone.
  1621. Also, the partial word is echoed as it is typed.
  1622. There is no need for an abbreviation to be a single keystroke,
  1623. as it should be with a macro.
  1624. .NH 2
  1625. Abbreviations
  1626. .PP
  1627. The editor has a number of short
  1628. commands which abbreviate longer commands which we
  1629. have introduced here.  You can find these commands easily
  1630. on the quick reference card.
  1631. They often save a bit of typing and you can learn them as convenient.
  1632. .NH 1
  1633. Nitty-gritty details
  1634. .NH 2
  1635. Line representation in the display
  1636. .PP
  1637. The editor folds long logical lines onto many physical lines in the display.
  1638. Commands which advance lines advance logical lines and will skip
  1639. over all the segments of a line in one motion.  The command \fB|\fR moves
  1640. the cursor to a specific column, and may be useful for getting near the
  1641. middle of a long line to split it in half.  Try \fB80|\fR on a line which
  1642. is more than 80 columns long.\*(dg
  1643. .FS
  1644. \*(dg You can make long lines very easily by using \fBJ\fR to join together
  1645. short lines.
  1646. .FE
  1647. .PP
  1648. The editor only puts full lines on the display; if there is not enough
  1649. room on the display to fit a logical line, the editor leaves the physical
  1650. line empty, placing only an @ on the line as a place holder.  When you
  1651. delete lines on a dumb terminal, the editor will often just clear the
  1652. lines to @ to save time (rather than rewriting the rest of the screen.)
  1653. You can always maximize the information on the screen by giving the \fB^R\fR
  1654. command.
  1655. .PP
  1656. If you wish, you can have the editor place line numbers before each line
  1657. on the display.  Give the command \fB:se nu\fR\s-2CR\s0 to enable
  1658. this, and the command \fB:se nonu\fR\s-2CR\s0 to turn it off.
  1659. You can have tabs represented as \fB^I\fR and the ends of lines indicated
  1660. with `$' by giving the command \fB:se list\fR\s-2CR\s0;
  1661. \fB:se nolist\fR\s-2CR\s0 turns this off.
  1662. .PP
  1663. Finally, lines consisting of only the character `~' are displayed when
  1664. the last line in the file is in the middle of the screen.  These represent
  1665. physical lines which are past the logical end of file.
  1666. .NH 2
  1667. Counts
  1668. .PP
  1669. Most
  1670. .I vi
  1671. commands will use a preceding count to affect their behavior in some way.
  1672. The following table gives the common ways in which the counts are used:
  1673. .DS
  1674. .TS
  1675. l lb.
  1676. new window size    :  /  ?  [[  ]]  \`  \'
  1677. scroll amount    ^D  ^U
  1678. line/column number    z  G  |
  1679. repeat effect    \fRmost of the rest\fP
  1680. .TE
  1681. .DE
  1682. .PP
  1683. The editor maintains a notion of the current default window size.
  1684. On terminals which run at speeds greater than 1200 baud
  1685. the editor uses the full terminal screen.
  1686. On terminals which are slower than 1200 baud
  1687. (most dialup lines are in this group)
  1688. the editor uses 8 lines as the default window size.
  1689. At 1200 baud the default is 16 lines.
  1690. .PP
  1691. This size is the size used when the editor clears and refills the screen
  1692. after a search or other motion moves far from the edge of the current window.
  1693. The commands which take a new window size as count all often cause the
  1694. screen to be redrawn.  If you anticipate this, but do not need as large
  1695. a window as you are currently using, you may wish to change the screen
  1696. size by specifying the new size before these commands.
  1697. In any case, the number of lines used on the screen will expand if you
  1698. move off the top with a \fB\-\fR or similar command or off the bottom
  1699. with a command such as \s-2RETURN\s0 or \fB^D\fR.
  1700. The window will revert to the last specified size the next time it is
  1701. cleared and refilled.\*(dg
  1702. .FS
  1703. \*(dg But not by a \fB^L\fR which just redraws the screen as it is.
  1704. .FE
  1705. .PP
  1706. The scroll commands \fB^D\fR and \fB^U\fR likewise remember the amount
  1707. of scroll last specified, using half the basic window size initially.
  1708. The simple insert commands use a count to specify a repetition of the
  1709. inserted text.  Thus \fB10a+\-\-\-\-\fR\s-2ESC\s0 will insert a grid-like
  1710. string of text.
  1711. A few commands also use a preceding count as a line or column number.
  1712. .PP
  1713. Except for a few commands which ignore any counts (such as \fB^R\fR),
  1714. the rest of the editor commands use a count to indicate a simple repetition
  1715. of their effect.  Thus \fB5w\fR advances five words on the current line,
  1716. while \fB5\fR\s-2RETURN\s0 advances five lines.  A very useful instance
  1717. of a count as a repetition is a count given to the \fB.\fR command, which
  1718. repeats the last changing command.  If you do \fBdw\fR and then \fB3.\fR,
  1719. you will delete first one and then three words.  You can then delete
  1720. two more words with \fB2.\fR.
  1721. .NH 2
  1722. More file manipulation commands
  1723. .PP
  1724. The following table lists the file manipulation commands which you can
  1725. use when you are in
  1726. .I vi.
  1727. .KF
  1728. .DS
  1729. .TS
  1730. lb l.
  1731. :w    write back changes
  1732. :wq    write and quit
  1733. :x    write (if necessary) and quit (same as ZZ).
  1734. :e \fIname\fP    edit file \fIname\fR
  1735. :e!    reedit, discarding changes
  1736. :e + \fIname\fP    edit, starting at end
  1737. :e +\fIn\fP    edit, starting at line \fIn\fP
  1738. :e #    edit alternate file
  1739. :w \fIname\fP    write file \fIname\fP
  1740. :w! \fIname\fP    overwrite file \fIname\fP
  1741. :\fIx,y\fPw \fIname\fP    write lines \fIx\fP through \fIy\fP to \fIname\fP
  1742. :r \fIname\fP    read file \fIname\fP into buffer
  1743. :r !\fIcmd\fP    read output of \fIcmd\fP into buffer
  1744. :n    edit next file in argument list
  1745. :n!    edit next file, discarding changes to current
  1746. :n \fIargs\fP    specify new argument list
  1747. :ta \fItag\fP    edit file containing tag \fItag\fP, at \fItag\fP
  1748. .TE
  1749. .DE
  1750. .KE
  1751. All of these commands are followed by a \s-2CR\s0 or \s-2ESC\s0.
  1752. The most basic commands are \fB:w\fR and \fB:e\fR.
  1753. A normal editing session on a single file will end with a \fBZZ\fR command.
  1754. If you are editing for a long period of time you can give \fB:w\fR commands
  1755. occasionally after major amounts of editing, and then finish
  1756. with a \fBZZ\fR.   When you edit more than one file, you can finish
  1757. with one with a \fB:w\fR and start editing a new file by giving a \fB:e\fR
  1758. command,
  1759. or set
  1760. .I autowrite
  1761. and use \fB:n\fP <file>.
  1762. .PP
  1763. If you make changes to the editor's copy of a file, but do not wish to
  1764. write them back, then you must give an \fB!\fR after the command you
  1765. would otherwise use; this forces the editor to discard any changes
  1766. you have made.  Use this carefully.
  1767. .ne 1i
  1768. .PP
  1769. The \fB:e\fR command can be given a \fB+\fR argument to start at the
  1770. end of the file, or a \fB+\fR\fIn\fR argument to start at line \fIn\fR\^.
  1771. In actuality, \fIn\fR may be any editor command not containing a space,
  1772. usefully a scan like \fB+/\fIpat\fR or \fB+?\fIpat\fR.
  1773. In forming new names to the \fBe\fR command, you can use the character
  1774. \fB%\fR which is replaced by the current file name, or the character
  1775. \fB#\fR which is replaced by the alternate file name.
  1776. The alternate file name is generally the last name you typed other than
  1777. the current file.  Thus if you try to do a \fB:e\fR and get a diagnostic
  1778. that you haven't written the file, you can give a \fB:w\fR command and
  1779. then a \fB:e #\fR command to redo the previous \fB:e\fR.
  1780. .PP
  1781. You can write part of the buffer to a file by finding out the lines
  1782. that bound the range to be written using \fB^G\fR, and giving these
  1783. numbers after the \fB:\fR
  1784. and before the \fBw\fP, separated by \fB,\fR's.
  1785. You can also mark these lines with \fBm\fR and
  1786. then use an address of the form \fB\(aa\fR\fIx\fR\fB,\fB\(aa\fR\fIy\fR
  1787. on the \fBw\fR command here.
  1788. .PP
  1789. You can read another file into the buffer after the current line by using
  1790. the \fB:r\fR command.
  1791. You can similarly read in the output from a command, just use \fB!\fR\fIcmd\fR
  1792. instead of a file name.
  1793. .PP
  1794. If you wish to edit a set of files in succession, you can give all the
  1795. names on the command line, and then edit each one in turn using the command
  1796. \fB:n\fR.  It is also possible to respecify the list of files to be edited
  1797. by giving the \fB:n\fR command a list of file names, or a pattern to
  1798. be expanded as you would have given it on the initial
  1799. .I vi
  1800. command.
  1801. .PP
  1802. If you are editing large programs, you will find the \fB:ta\fR command
  1803. very useful.  It utilizes a data base of function names and their locations,
  1804. which can be created by programs such as
  1805. .I ctags,
  1806. to quickly find a function whose name you give.
  1807. If the \fB:ta\fR command will require the editor to switch files, then
  1808. you must \fB:w\fR or abandon any changes before switching.  You can repeat
  1809. the \fB:ta\fR command without any arguments to look for the same tag
  1810. again.
  1811. .NH 2
  1812. More about searching for strings
  1813. .PP
  1814. When you are searching for strings in the file with \fB/\fR and \fB?\fR,
  1815. the editor normally places you at the next or previous occurrence
  1816. of the string.  If you are using an operator such as \fBd\fR,
  1817. \fBc\fR or \fBy\fR, then you may well wish to affect lines up to the
  1818. line before the line containing the pattern.  You can give a search of
  1819. the form \fB/\fR\fIpat\fR\fB/\-\fR\fIn\fR to refer to the \fIn\fR'th line
  1820. before the next line containing \fIpat\fR, or you can use \fB+\fR instead
  1821. of \fB\-\fR to refer to the lines after the one containing \fIpat\fR.
  1822. If you don't give a line offset, then the editor will affect characters
  1823. up to the match place, rather than whole lines; thus use ``+0'' to affect
  1824. to the line which matches.
  1825. .PP
  1826. You can have the editor ignore the case of words in the searches it does
  1827. by giving the command \fB:se ic\fR\s-2CR\s0.
  1828. The command \fB:se noic\fR\s-2CR\s0 turns this off.
  1829. .ne 1i
  1830. .PP
  1831. Strings given to searches may actually be regular expressions.
  1832. If you do not want or need this facility, you should
  1833. .DS
  1834. set nomagic
  1835. .DE
  1836. in your EXINIT.
  1837. In this case, 
  1838. only the characters \fB\(ua\fR and \fB$\fR are special in patterns.
  1839. The character \fB\e\fR is also then special (as it is most everywhere in
  1840. the system), and may be used to get at the
  1841. an extended pattern matching facility.
  1842. It is also necessary to use a \e before a
  1843. \fB/\fR in a forward scan or a \fB?\fR in a backward scan, in any case.
  1844. The following table gives the extended forms when \fBmagic\fR is set.
  1845. .DS
  1846. .TS
  1847. lb l.
  1848. \(ua    at beginning of pattern, matches beginning of line
  1849. $    at end of pattern, matches end of line
  1850. \fB\&.\fR    matches any character
  1851. \e<    matches the beginning of a word
  1852. \e>    matches the end of a word
  1853. [\fIstr\fP]    matches any single character in \fIstr\fP
  1854. [\(ua\fIstr\fP]    matches any single character not in \fIstr\fP
  1855. [\fIx\fP\-\fIy\fP]    matches any character between \fIx\fP and \fIy\fP
  1856. *    matches any number of the preceding pattern
  1857. .TE
  1858. .DE
  1859. If you use \fBnomagic\fR mode, then
  1860. the \fB. [\fR and \fB*\fR primitives are given with a preceding
  1861. \e.
  1862. .NH 2
  1863. More about input mode
  1864. .PP
  1865. There are a number of characters which you can use to make corrections
  1866. during input mode.  These are summarized in the following table.
  1867. .sp .5
  1868. .DS
  1869. .TS
  1870. lb l.
  1871. ^H    deletes the last input character
  1872. ^W    deletes the last input word, defined as by \fBb\fR
  1873. erase    your erase character, same as \fB^H\fP
  1874. kill    your kill character, deletes the input on this line
  1875. \e    escapes a following \fB^H\fP and your erase and kill
  1876. \s-2ESC\s0    ends an insertion
  1877. \s-2DEL\s0    interrupts an insertion, terminating it abnormally
  1878. \s-2CR\s0    starts a new line
  1879. ^D    backtabs over \fIautoindent\fP
  1880. 0^D    kills all the \fIautoindent\fP
  1881. \(ua^D    same as \fB0^D\fP, but restores indent next line
  1882. ^V    quotes the next non-printing character into the file
  1883. .TE
  1884. .DE
  1885. .sp .5
  1886. .PP
  1887. The most usual way of making corrections to input is by typing \fB^H\fR
  1888. to correct a single character, or by typing one or more \fB^W\fR's to
  1889. back over incorrect words.  If you use \fB#\fR as your erase character
  1890. in the normal system, it will work like \fB^H\fR.
  1891. .PP
  1892. Your system kill character, normally \fB@\fR, \fB^X\fP or \fB^U\fR,
  1893. will erase all
  1894. the input you have given on the current line.
  1895. In general, you can neither
  1896. erase input back around a line boundary nor can you erase characters
  1897. which you did not insert with this insertion command.  To make corrections
  1898. on the previous line after a new line has been started you can hit \s-2ESC\s0
  1899. to end the insertion, move over and make the correction, and then return
  1900. to where you were to continue.  The command \fBA\fR which appends at the
  1901. end of the current line is often useful for continuing.
  1902. .PP
  1903. If you wish to type in your erase or kill character (say # or @) then
  1904. you must precede it with a \fB\e\fR, just as you would do at the normal
  1905. system command level.  A more general way of typing non-printing characters
  1906. into the file is to precede them with a \fB^V\fR.  The \fB^V\fR echoes
  1907. as a \fB\(ua\fR character on which the cursor rests.  This indicates that
  1908. the editor expects you to type a control character.  In fact you may
  1909. type any character and it will be inserted into the file at that point.*
  1910. .FS
  1911. * This is not quite true.  The implementation of the editor does
  1912. not allow the \s-2NULL\s0 (\fB^@\fR) character to appear in files.  Also
  1913. the \s-2LF\s0 (linefeed or \fB^J\fR) character is used by the editor
  1914. to separate lines in the file, so it cannot appear in the middle of a
  1915. line.  You can insert any other character, however, if you wait for the
  1916. editor to echo the \fB\(ua\fR before you type the character.  In fact,
  1917. the editor will treat a following letter as a request for the corresponding
  1918. control character.  This is the only way to type \fB^S\fR or \fB^Q\fP,
  1919. since the system normally uses them to suspend and resume output
  1920. and never gives them to the editor to process.
  1921. .FE
  1922. .PP
  1923. If you are using \fIautoindent\fR you can backtab over the indent which
  1924. it supplies by typing a \fB^D\fR.  This backs up to a \fIshiftwidth\fR
  1925. boundary.
  1926. This only works immediately after the supplied \fIautoindent\fR.
  1927. .PP
  1928. When you are using \fIautoindent\fR you may wish to place a label at
  1929. the left margin of a line.  The way to do this easily is to type \fB\(ua\fR
  1930. and then \fB^D\fR.  The editor will move the cursor to the left margin
  1931. for one line, and restore the previous indent on the next.  You can also
  1932. type a \fB0\fR followed immediately by a \fB^D\fR if you wish to kill
  1933. all the indent and not have it come back on the next line.
  1934. .NH 2
  1935. Upper case only terminals
  1936. .PP
  1937. If your terminal has only upper case, you can still use
  1938. .I vi
  1939. by using the normal
  1940. system convention for typing on such a terminal.
  1941. Characters which you normally type are converted to lower case, and you
  1942. can type upper case letters by preceding them with a \e.
  1943. The characters { ~ } | \(ga are not available on such terminals, but you
  1944. can escape them as \e( \e\(ua \e) \e! \e\(aa.
  1945. These characters are represented on the display in the same way they
  1946. are typed.\*(dd
  1947. .FS
  1948. \*(dd The \e character you give will not echo until you type another
  1949. key.
  1950. .FE
  1951. .NH 2
  1952. Vi and ex
  1953. .PP
  1954. .I Vi
  1955. is actually one mode of editing within the editor
  1956. .I ex.
  1957. When you are running
  1958. .I vi
  1959. you can escape to the line oriented editor of
  1960. .I ex
  1961. by giving the command
  1962. \fBQ\fR.
  1963. All of the
  1964. .B :
  1965. commands which were introduced above are available in
  1966. .I ex.
  1967. Likewise, most
  1968. .I ex
  1969. commands can be invoked from
  1970. .I vi
  1971. using :.
  1972. Just give them without the \fB:\fR and follow them with a \s-2CR\s0.
  1973. .PP
  1974. In rare instances, an internal error may occur in
  1975. .I vi.
  1976. In this case you will get a diagnostic and be left in the command mode of
  1977. .I ex.
  1978. You can then save your work and quit if you wish by giving a command
  1979. \fBx\fR after the \fB:\fR which \fIex\fR prompts you with, or you can
  1980. reenter \fIvi\fR by giving
  1981. .I ex
  1982. a
  1983. .I vi
  1984. command.
  1985. .PP
  1986. There are a number of things which you can do more easily in
  1987. .I ex
  1988. than in
  1989. .I vi.
  1990. Systematic changes in line oriented material are particularly easy.
  1991. You can read the advanced editing documents for the editor
  1992. .I ed
  1993. to find out a lot more about this style of editing.
  1994. Experienced
  1995. users often mix their use of
  1996. .I ex
  1997. command mode and
  1998. .I vi
  1999. command mode to speed the work they are doing.
  2000. .NH 2
  2001. Open mode: vi on hardcopy terminals and ``glass tty's''
  2002. \(dd
  2003. .PP
  2004. If you are on a hardcopy terminal or a terminal which does not have a cursor
  2005. which can move off the bottom line, you can still use the command set of
  2006. .I vi,
  2007. but in a different mode.
  2008. When you give a
  2009. .I vi
  2010. command, the editor will tell you that it is using
  2011. .I open
  2012. mode.
  2013. This name comes from the
  2014. .I open
  2015. command in
  2016. .I ex,
  2017. which is used to get into the same mode.
  2018. .PP
  2019. The only difference between
  2020. .I visual
  2021. mode
  2022. and
  2023. .I open
  2024. mode is the way in which the text is displayed.
  2025. .PP
  2026. In
  2027. .I open
  2028. mode the editor uses a single line window into the file, and moving backward
  2029. and forward in the file causes new lines to be displayed, always below the
  2030. current line.
  2031. Two commands of
  2032. .I vi
  2033. work differently in
  2034. .I open:
  2035. .B z
  2036. and
  2037. \fB^R\fR.
  2038. The
  2039. .B z
  2040. command does not take parameters, but rather draws a window of context around
  2041. the current line and then returns you to the current line.
  2042. .PP
  2043. If you are on a hardcopy terminal,
  2044. the
  2045. .B ^R
  2046. command will retype the current line.
  2047. On such terminals, the editor normally uses two lines to represent the
  2048. current line.
  2049. The first line is a copy of the line as you started to edit it, and you work
  2050. on the line below this line.
  2051. When you delete characters, the editor types a number of \e's to show
  2052. you the characters which are deleted.  The editor also reprints the current
  2053. line soon after such changes so that you can see what the line looks
  2054. like again.
  2055. .PP
  2056. It is sometimes useful to use this mode on very slow terminals which
  2057. can support
  2058. .I vi
  2059. in the full screen mode.
  2060. You can do this by entering
  2061. .I ex
  2062. and using an
  2063. .I open
  2064. command.
  2065. .LP
  2066. .SH
  2067. Acknowledgements
  2068. .PP
  2069. Bruce Englar encouraged the early development of this display editor.
  2070. Peter Kessler helped bring sanity to version 2's command layout.
  2071. Bill Joy wrote versions 1 and 2.0 through 2.7,
  2072. and created the framework that users see in the present editor.
  2073. Mark Horton added macros and other features and made the
  2074. editor work on a large number of terminals and Unix systems.
  2075.