Previous Table of Contents Next


1.  Type vi .exrc .tags .profile and press Return.
2.  Press i and enter the following lines of text; press Return at the end of each line.
     The i places you in insert mode.
     To escape from insert mode you press the Esc key, but don't do that yet.
     First let's enter a few more lines of text.
     This should be enough for now. Press the Esc key after typing this line.
3.  Press Esc to exit insert mode.
4.  Type 1G to move the cursor to the first line of the buffer.
5.  Type yG to yank the text from the current line to the end of the buffer to the undo (unnamed) register. If your cursor remains at the top of the buffer, type G to move it to the bottom line.
6.  Now type p (lowercase) to put the contents of the undo buffer back in the session buffer.
     The i places you in insert mode.
     To escape from insert mode you press the Esc key, but don't do that yet.
     First let's enter a few more lines of text.
     This should be enough for now. Press the Esc key after typing this line.
   The i places you in insert mode.
   To escape from insert mode you press the Esc key, but don't do that yet.
   First let's enter a few more lines of text.
   This should be enough for now. Press the Esc key after typing this line.
7.  Type 4k to move up four lines.
8.  Type 2j to move down two lines.
9.  Type 3l (three lowercase Ls) to move to the right three spaces.
10.  Type cw to change the word escape. Notice the $ sign at the end of the word escape. This notifies you of what text you are changing. You are in insert mode until you press the Esc key.
11.  Now type exit and press Esc to exit insert mode.
12.  Type H to move to the top left corner of the screen.
13.  Now type dL to delete all of lines from the current position to the last line on the screen.
14.  To retrieve the text you just deleted type u. The text returns to your screen. Remember, the u command only undoes the last text manipulation commands.
15.  Now type PPP to put three more copies of the deleted text in the session buffer.
16.  Now type 4Ctrl-E to move the screen down four lines. If your version of vi does not support counts then press Ctrl-E four times.
17.  Type /First and press Return. Notice when you pressed the / the cursor jumped to the last line on the screen and placed the / there. This is the search facility of vi. The ? searches in the reverse direction. Notice after you pressed Return, the cursor appeared at the first occurrence of the word First.
18.  Type wwww to move the cursor to the next word, four times. Notice the cursor stopped on the ' (single quote) of let's. The small letter word movement commands are punctuation sensitive. The uppercase commands ignore punctuation.
19.  Type BB and watch how the cursor jumps past the ' without stopping.
20.  To jump to the end of the current line type $.
21.  To jump to the beginning of the current line type 0.
22.  Now sort the entire buffer. Type 1G to go to line 1 of the buffer.
23.  Type !Gsort and press Return to send the contents of the buffer to the UNIX sort command. The ! signals vi to filter text based on the following motion command. The motion command used is the G, which goes to the last line of the buffer. Notice all of the lines in the buffer are sorted.
24.  Now delete all the lines from the buffer by typing :%d. The : enters temporary ex mode, the % is the alias for line 1,$ (all lines in the buffer), and the d is the delete command. An alternative command is 1GdG.
25.  Now create a .exrc type file by typing i to enter insert mode.
26.  Type the following lines to create a .exrc file you can use when you enter vi.
   set wm=8
   set ai
   map ^Z :sh^V^M
   map v :w^V^M:n^V^M
   set tags=/u1/ts/mylogin/.tags<Escape>

The first line sets your wrap margin to 8. This causes vi to insert carriage returns in your text automatically when you type past the 72 (80-8=72) column. The second line sets autoindent. The third maps Ctrl-Z to :sh<Return>; the Ctrl-V is needed to escape the meaning of the Return. The third line maps v to be :w<Return>:n<Return> which writes your file to disk and advances you to the next file to edit. The last line sets your tags file path to your HOME directory with the filename of .tags.
27.  Type :w and press Return to save the buffer to disk.
28.  Now type :so % and press Return to have vi read and interpret the commands in the .exrc file.
29.  To see the two maps you stored in the .exrc file type :map and press Return.
30.  Press Return to return to the vi screen.
31.  Type v to write this file again and move to the next file, .tags.

In this file we create a tags file for some of the standard files you may need to edit from time to time.

1.  Type :arg to list the current files being edited.
    :arg
    .exrc [.tags] .profile

The brackets around .tags indicate that .tags is the current file being edited.
2.  Type the following lines of text; press Return after each line.
   exrc    /u1/ts/mylogin/.exrc    1
   profile /u1/ts/mylogin/.profile 1
   tags    /u1/ts/mylogin/.tags    1

The first line defines a label of exrc so when a tag of exrc is specified the $HOME/.exrc file is edited starting at line 1. The next two lines perform the same function for the tags file and the profile files.

NOTE:  
The tags file must be sorted in alphabetical order or the tags command will not function properly.



3.  Save your .tags file to disk by typing :w and pressing Return.
4.  Now to edit your .exrc type :tag exrc and press Return. Notice the editor changes the screen and informs you that you are editing the .exrc file.
5.  To return to the .tags file buffer, type :e# and press Return. The # sign represents the alternate buffer name.
6.  Enough editing, exit the editor by typing ZZ. vi should complain about having another file to edit. Since we don't wish to edit the file, type ZZ again or type :q! to override the warning signal.
7.  Turn to Module 108 to continue the learning sequence.


Previous Table of Contents Next