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
- Log into the system.
- 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
- Correct any typing errors made during creation.
- Make a backup copy of your file.
- Use the move cursor commands to move the cursor to the first "g" in the third line
(the character "g" of the word "good").
- Insert an invisible mark there.
- Use the G command to move to the end of the file.
- Place the cursor at the last character of the last line using the $ command.
- Using a block object, yank the block between the cursor position and the marked point.
- Move the cursor to the beginning of the file.
- Use the put command to insert the yank buffer before the current position.
- Quit vi without saving the file (you should move to ex mode first).
- You may log out, or continue with the following session.
Session H2
- Log into the system or change to your home directory.
- Use ex to open the file created in Session H1.
- Check the line number of the current line using the p command.
- Move the last two lines to the beginning of the file.
- Move the first two lines (the ones you moved in the previous step) to the end of the file.
- Check the line number of the current line using the p command.
- Go to the second line.
- 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).
- Check the line number of the current line.
- Use backward search to find the line starting with "spirit."
- Delete the text from this line down to the end.
- Move to the vi editor.
- Save the file in the vi editor, using the name
AHS2F1
- 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.
- Log into the system or change to your home directory.
- Use the vi editor to create a file called
AHS3F1
- At the command mode, use the command
:set all to find which options are set
and which variables have values.
- Is the autoindent option set? If not, use the command
:set autoindent to set this option.
- Now move to the vi text input mode.
- 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.
- 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).
- Change to the command mode. Use the command
:set noautoindent
to unset the autoindent feature.
- 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?
- You may log out, or continue with the following session.
Session H4
In this session, we learn more about vi/ex customization.
- Log into the system or change to your home directory.
- Use the vi editor to create a file called
AHS4F1
- Use the manual and other sources to find out about the following options and
variables. Briefly write your findings for each item:
- ignorecase
- magic
- number, scroll
- scroll
- shiftwidth
- showmode
- wrapmargin
- Write the edit buffer back to the original file.
- Use each of the options or variables listed in the
AHS4F1 file.
- Quit from vi without saving.
- Print the file AHS4F1
- 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.
- Log into the system or change to your home directory.
- Use the vi editor to create a file called
AHS5F1
- 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)
- Use the abbreviations:
cost for college student
cis for computer information system
fq for fall quarter
jan for January
- Test each of the abbreviations listed in the AHS5F1 file.
- Use :unab cis to cancel the abbreviation for cis.
- Try to use the cis abbreviation again.
- Save the file.
- 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.
- Log into the system or change to your home directory.
- Use the vi editor to create a file called
AHS6F1
- 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
- Create and test each of the following abbreviations in the file:
:map 1 d0
:map 2 d$
:map 3 dd
- Save the file.
- 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
- Use the following command to create a file with your work from the assignment:
cat headingH sessionH1 sessionH2 sessionH3 sessionH4 sessionH5 sessionH6 > assignmentH.txt
-
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.
- Turn in your printout to the instructor on time.