Annotation of 43BSDTahoe/new/help/src/vi_practice, revision 1.1.1.1

1.1       root        1: #
                      2: cat << '%'
                      3: ##nroff
                      4: .TI VI_PRACTICE
                      5: Practice Session with the Visual Editor "vi"
                      6: .ds CF         \" prevents shell from stumbling on the final page number
                      7: .sp
                      8: This will initiate a practice session with the "vi" editor.
                      9: You will be placed in the editor with a file containing instructions
                     10: on how to proceed.
                     11: .sp
                     12: ##
                     13: '%'
                     14: cat > /tmp/hvi$$ << '%'
                     15: ---------------------------------------------------------------
                     16: If you get into trouble: to exit from vi press ESC and type ZZ
                     17: ---------------------------------------------------------------
                     18: 
                     19: First of all, we will practice moving around the screen.
                     20: Press the RETURN key to move down a line at a time.
                     21: Keep hitting RETURN until you arrive at the big X below.
                     22: Then use the arrow keys for directional movements.
                     23: 
                     24:                 ______  Start at the x below and move right.
                     25:                 |
                     26:                 V
                     27: 
                     28:                 X-----------------------x <-- You should be here.
                     29:                                         |       Now go down.
                     30:                                         |
                     31:                                         |
                     32:                                         |
                     33:                                         |
                     34:    This is the end. --> x               |
                     35: Now use CTRL-d to       |               |
                     36: scroll downwards.       |               |
                     37:                         |               |
                     38:                         |               |
                     39:                         |               |
                     40:                         |               |
                     41:                         |               |
                     42: You should be here. --> x---------------x <-- You should be here.
                     43:   Now go up.                                    Now move left.
                     44: 
                     45: Scrolling goes a few lines at a time.
                     46: If you want to scroll upwards, you could try the CTRL-u command.
                     47: CTRL-d goes down, whereas CTRL-u goes up.
                     48: 
                     49: Continue with CTRL-d until you're located around here.
                     50: 
                     51: To move a forward a word at a time, just type the letter w -- it
                     52: will not appear on the screen, but the cursor will jump to the
                     53: next word.  To go back a word at a time, try the b command.  There
                     54: is also the e command, which goes to the end of the current word.
                     55: Try moving around this paragraph with these three commands.
                     56: 
                     57: This is a block of text that is pretty boring.  Nonetheless,
                     58: there is an interesting word further down.  That word is Garbage.
                     59: Do a pattern search for this word.  To do this, type a slash (/),
                     60: then type the letters g a r b a g e (without spaces), and a RETURN.
                     61: Bla bla bla bla bla bla bla.  Bla bla bla bla.  Bla bla bla bla
                     62: bla bla bla bla bla.  Bla bla bla bla bla bla bla bla bla bla.
                     63: Bla bla bla bla bla bla bla.
                     64: 
                     65: I've had enough of this garbage.  <-- You should be on this line.
                     66: 
                     67: Now do another search for the same word.
                     68: To do this, type an "n", which will not appear on the screen.
                     69: You will be placed at the next instance of the word.
                     70: 
                     71: Another instance of the pattern "garbage".  <-- Here it is.
                     72: 
                     73: Now continue onwards by pressing RETURN a few times.
                     74: 
                     75: ---------------------------------------------------------------
                     76: If you get into trouble: to exit from vi press ESC and type ZZ
                     77: ---------------------------------------------------------------
                     78: 
                     79: Now that we've learned to move the cursor around the screen,
                     80: let's try several commands for changing the text.  The first is
                     81: the "a" command, which appends text-- everything you type will
                     82: be entered into your file, until you issue an ESC (this is a
                     83: button on the upper left corner of the keyboard).  Move down to
                     84: the line below the arrow, and add some text.  Don't forget to
                     85: end text input by pressing the ESC key.  After you're done,
                     86: move on to the lines below.
                     87: 
                     88: |
                     89: |
                     90: V
                     91: 
                     92: 
                     93: Good.  Remember, if you get into a weird state by pressing some
                     94: key you don't know about, you can always get out of the editor
                     95: and back to the shell by pressing ESC and typing ZZ (capital Z
                     96: two times in a row).  These characters will not appear on the
                     97: screen, but they will get you out of vi.
                     98: 
                     99: Now let's practice deleting characters with the x command.  The
                    100: lines below from Shakespeare have several extraneous characters;
                    101: delete them by moving to the extraneous character, and typing x,
                    102: as if you wanted to "x" them out on a typewriter.
                    103: 
                    104: Let me Nnot to the marBriage of trEue minds     <---
                    105: admitV impediRAments.
                    106: 
                    107: Good.  Now try deleting a line with the dd command.  Move down
                    108: to the line below, and type d twice in a row.  The d's will not
                    109: appear on the screen, but the line will disappear.
                    110: 
                    111: THiS liNe iS UggLy AnD wAnTs tO bE dELeTeD.     <---
                    112: 
                    113: Say you wanted to add a new line between two other lines.  In
                    114: the famous quote below, the fourth line is missing.  Just in case
                    115: you're not a John Donne fan, the fourth line is:
                    116: 
                    117:     And therefore never send to know for whom the bell tolls,
                    118: 
                    119: To open up a new line, move the cursor above where the new line
                    120: should go, type an o, which will move you onto the next line,
                    121: and then enter the text, ending with ESC (as with the a command).
                    122: 
                    123: No man is an island entire of itself;
                    124: Every man is a piece of the continent, a part of the main.
                    125: Any man's death dimishes me, because I am involved in mankind.
                    126: it tolls for thee.
                    127: 
                    128: With these four commands, a x dd and o, you can do anything you
                    129: want.  However, learning additional commands will make things
                    130: easier in the long run.  For instance, to split the following
                    131: line in half, you could go to the comma, type: a RETURN ESC, but
                    132: it would be easier to go to the space after the comma and type
                    133: r RETURN.  The r command replaces whatever is beneath the cursor
                    134: with whatever you type next.
                    135: 
                    136: This is an extremely long line, and needs to be split after the comma.
                    137: 
                    138: To join lines together again, go to the first line of the two
                    139: you wish to join, and issue the J command.  (It must be a capital
                    140: J, because a small j is reserved for down arrow.)
                    141: 
                    142: Two short lines
                    143: look better as one.
                    144: 
                    145: ---------------------------------------------------------------
                    146: If you get into trouble: to exit from vi press ESC and type ZZ
                    147: ---------------------------------------------------------------
                    148: 
                    149: One of the nicest features of vi is that it makes it possible to
                    150: combine movements and changes.  If you want to delete a single word,
                    151: for instance, you could move to the word and type x over and over
                    152: until the word is gone.  But it's easier to type dw -- which means
                    153: delete word.  Try this on the extra word in Shelley's line below:
                    154: 
                    155: I met a traveller traveller from an antique land
                    156: 
                    157: If you want to change a word, rather than deleting it, you could
                    158: type cw instead of dw -- cw stands for change word.  A dollar sign
                    159: will appear at the end of the word, and whatever you type, until
                    160: you press ESC, will replace the original word.  Replace the word
                    161: "enormous" with Shelley's original word, "vast":
                    162: 
                    163: Who said: Two enormous and trunkless legs of stone
                    164: 
                    165: Many commands take arguments indicating their scope.  It would be
                    166: painful to delete many lines unless this were the case.  Delete
                    167: the three lines below by using the 3dd command, meaning, perform
                    168: the dd command three times:
                    169: 
                    170: THiS liNe iS UggLy AnD wAnTs tO bE dELeTeD.             <---
                    171: THiS liNe iS aLSo UggLy AnD wAnTs tO bE dELeTeD.        <---
                    172: THiS liNe, tOo, iS UggLy AnD wAnTs tO bE dELeTeD.       <---
                    173: 
                    174: Good.  Now you're really blasting away those lines.  Don't forget
                    175: that the u command always undoes the last change.  Try typing u
                    176: now, and see those 3 lines come back.  Try u once more, and see
                    177: them disappear again.  Undo is its own inverse.
                    178: 
                    179: Oftentimes people who type quickly transpose characters.  To fix
                    180: this problem, move to the first character of the transposed pair,
                    181: and issue an xp command -- this stands for x out and put.  Mend
                    182: the word below, whose second and third characters are skewed:
                    183: 
                    184:         hpyerventilate
                    185: 
                    186: That's it for this session.  If you want to write your changes,
                    187: leave the editor with the ZZ command.  If you want to leave your
                    188: text the way it was before, type :q! to quit without writing. 
                    189: '%'
                    190: echo -n "Do you want to continue?  "
                    191: if ($< !~ y*) then
                    192:        echo "OK"
                    193: else
                    194:        vi /tmp/hvi$$
                    195: endif
                    196: rm -f /tmp/hvi$$

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.