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