Assignment H

General instructions for all assignments

Provide an answer for each item in each session.
When the answer to the item is a Unix command, show the command and the system's response.
When the system prints more than 5 lines, abbreviate the response to 5 lines (unless more lines are specifically requested), showing the most important parts.
Use vi to create a file for each session, for example, create a file named sessionH1

Show all the vi and ex commands you use

Session H1

  1. Log into the system.
  2. Use the vi editor to create a file called   AHS1F1   that contains the following paragraph with the same alignment and format.
    People naturally fear misfortune and hope for good
    fortune. But if the distinction is carefully studied,
    misfortune often turns out to be good fortune and good
    fortune to be misfortune. The wise person learns
    to meet life's changing circumstances with an equitable
    spirit, being neither elated by success nor depressed
    by failure.
    Buddha
          
  3. Correct any typing errors made during creation.
  4. Make a backup copy of your file.
  5. Use the move cursor commands to move the cursor to the first "g" in the third line (the character "g" of the word "good").
  6. Insert an invisible mark there.
  7. Use the G command to move to the end of the file.
  8. Place the cursor at the last character of the last line using the $ command.
  9. Using a block object, yank the block between the cursor position and the marked point.
  10. Move the cursor to the beginning of the file.
  11. Use the put command to insert the yank buffer before the current position.
  12. Quit vi without saving the file (you should move to ex mode first).
  13. You may log out, or continue with the following session.

Session H2

  1. Log into the system or change to your home directory.
  2. Use ex to open the file created in Session H1.
  3. Check the line number of the current line using the p command.
  4. Move the last two lines to the beginning of the file.
  5. Move the first two lines (the ones you moved in the previous step) to the end of the file.
  6. Check the line number of the current line using the p command.
  7. Go to the second line.
  8. Use the copy command to copy the line starting with "spirit" and the next two lines to the end of the file (using the range command with the semicolon separator).
  9. Check the line number of the current line.
  10. Use backward search to find the line starting with "spirit."
  11. Delete the text from this line down to the end.
  12. Move to the vi editor.
  13. Save the file in the vi editor, using the name   AHS2F1  
  14. You may log out, or continue with the following session.

Session H3

The vi and ex editor can be used together. In vi we type a colon (:) when we want to use an ex command. In this session, we learn how to customize the vi/ex editor. This editor uses options and variables to customize its environment. The option is an on/off switch that can be set or unset. A variable can hold a numeric or string value for use during the editing process. In this session, we show you how to check these settings and how to change them.

  1. Log into the system or change to your home directory.
  2. Use the vi editor to create a file called   AHS3F1  
  3. At the command mode, use the command   :set all   to find which options are set and which variables have values.
  4. Is the autoindent option set? If not, use the command   :set autoindent   to set this option.
  5. Now move to the vi text input mode.
  6. Use a tab at the beginning of the line to indent the first line in the file, and type some text in the first line.
  7. Type a second line. What do you see? Is the second line inserted and indented automatically? Is it aligned with the first line? This feature can be used when we want to create lines that need alignment (such as lines in a programming language).
  8. Change to the command mode. Use the command   :set noautoindent   to unset the autoindent feature.
  9. Now move the cursor to the last line of the file, change to the input mode, and type another line. What do you see? Is the line indented?
  10. You may log out, or continue with the following session.

Session H4

In this session, we learn more about vi/ex customization.

  1. Log into the system or change to your home directory.
  2. Use the vi editor to create a file called   AHS4F1  
  3. Use the manual and other sources to find out about the following options and variables. Briefly write your findings for each item:
  4. Write the edit buffer back to the original file.
  5. Use each of the options or variables listed in the   AHS4F1   file.
  6. Quit from vi without saving.
  7. Print the file   AHS4F1
  8. You may log out, or continue with the following session.

Session H5

In this session, we learn more about vi/ex customization by using abbreviations.

  1. Log into the system or change to your home directory.
  2. Use the vi editor to create a file called   AHS5F1  
  3. Use the manual and other sources to find out about the abbreviation command. This command allows you to use abbreviations for commonly used words. The operator can be used as follows:
      :ab x y   (x is abbreviation for y)
  4. Use the abbreviations:
    cost   for    college student
    cis    for    computer information system
    fq     for    fall quarter
    jan    for    January
          
  5. Test each of the abbreviations listed in the   AHS5F1   file.
  6. Use   :unab cis   to cancel the abbreviation for cis.
  7. Try to use the cis abbreviation again.
  8. Save the file.
  9. You may log out, or continue with the following session.

Session H6

In this session, we learn more about vi/ex customization by using macros.

  1. Log into the system or change to your home directory.
  2. Use the vi editor to create a file called   AHS6F1  
  3. Use the manual and other sources to find about the macros and map operators. This command allows the definition of a key for a complex command. The format of the command is:   :map key command  
  4. Create and test each of the following abbreviations in the file:
    :map 1 d0
    :map 2 d$
    :map 3 dd
          
  5. Save the file.
  6. Log out of the system.

Submission session

Create a heading similar to the heading for assignment A.

Tommy Atkins   replace with your name
CIS 18A    
Winter 2011   replace with the current quarter
Assignment H   replace with the current assignment letter

  1. Use the following command to create a file with your work from the assignment:
    cat headingH sessionH1 sessionH2 sessionH3 sessionH4 sessionH5 sessionH6 > assignmentH.txt
  2. Use e-mail or WinSCP to obtain a copy of assignmentA.txt. Print it using notepad, or otherwise use the Courier New or other mono-space font.
  3. Turn in your printout to the instructor on time.