In this terminal session, you will create a small text file and practice using the editing
keys that vi provides. Use your imagination. Do not limit yourself to the small file in
Try to use all the keys that are explained in this chapter.
1. Use the vi editor to create a file called Chapter4 and type in the text shown on
2. Save this file
The vi history
The vi editor was developed at the University of california, berkeley
as part of the berkeley unix system.
"Chapter4" [new file ]
3. Open the test file again and add text to make it look like the text shown on screen 2.
4. Save this file again.
The vi history
The vi editor was developed at the University of california
berkeley as part of the berkeley unix system.
At the beginning the vi editor was part of another editor
The vi part of the ex editor was often used and became very.
This popularity forced the developers to come up with a separate
now the vi editor is independent of the ex editor and is available on
most of the UNIX operating system.
The vi editor is a good editor for everyday editing jobs.
5. Open the test file once more and edit the text to make it look like the text on screen 3.
6. Search for the word vi using the / (forward search). Use n to find the next occurrence
of the word vi.
7. Search for the word vi using the ? (backward search). Use n to find the next occurrence
of the word vi.
8. Place the cursor at the beginning of the file and delete five lines. Undo your delete.
9. Place the cursor at the beginning of the second line and delete 10 characters. Undo
10. Use r to replace the character at the cursor position. Undo your action.
11. Use R to change the word developers to creators. Undo your action.
12. If you have a Linux system, practice the following:
a. Get help for the help command.
b. Get help for the ZZ command.
c. Get help for the search command.
13. Save your file for later exercise sessions using the ZZ command.
The vi history
The vi editor was developed at the University of California
Berkeley as part of the Berkeley UNIX system.
At the beginning the vi (visual) editor was part of the ex editor
and you had to be in the ex editor to use the vi editor.
The vi part of the ex editor was often used and became
very popular. This popularity forced the developers to come up
with a separate vi editor.
Now the vi editor is independent of the ex editor and is available
on most of the UNIX operating systems.
The vi editor is a good, efficient editor for everyday editing jobs
although it could be more user friendly.
Try the following commands. Observe the output and the command feedback (error messages on the screen and so on) on the screen
Create a directory structure in your HOME directory and try different commands until you feel comfortable with directories and file manipulation commands.
- Show your current directory
- Change your HOME directory
- Identify your HOME directory
- List the contents of your current directory
- Create a new directory called xyz under your current directory
- Create a file called xyz in the xyz directory
- Identify the directions in your working directory
- Show the contents of your current directory
- In reverse alphabetical order
- In long format
- In horizontal format
- Showing the invisible files in your current directory
- What is the command line to open a file named xyz in read only mode?
- What is the command line to open a file names xyz with cursor on the line with first occurrence of the word UNIX?
- What is view?
- What are the numbered buffers?
- What are the named buffers?
- What is the vi command to
- Delete a line
- Delete a word
- Copy a line
- Copy a word
- Delete to the end of the current line
- Save two lines in a buffer called z?
- Copy the contents of the z buffer after the current line?
- Copy the contents of the buffer two after the current line?
- What is the vi command for removing the showmode option?
- What is the vi command to abbreviate ‘one two three’ to ‘123’
- What is the .exrc file? When is the .exrc file executed?
- What is the command to execute a shell command such as date while in vi?
- What is the command to read the current date and place it in the file under the current line?
- What is the set command for vi to display confirmation messages?
- What is the vi file recovery option?
- What is the command to get the list of the file that were saved before crash?
- What is the vim editor
- Match the commands shown in the left column with explanations shown in the right. All the commands are applicable only in the command mode.
- G a. Replaces the character under the cursor with the letter x.
- /most b. Places the cursor on the last line in the file
- [Ctrl-g] c. copies four lines in the buffer x
- 2dw d. Moves the cursor down one line
- j e. shows the line number of the current line
- “x4yy f. Positions the cursor on line 66
- $ g. Deletes the character under the cursor
- 0 (zero) h. retrieves the contents of buffer 1
- 66G i. Deletes two words
- x j. Positions the cursor at the end of the current line
- rx k. Finds the word most
- “lp l. Positions the cursor at the beginning of the current line
- While using the vi editor, what command do you use to
- Set the line number position?
- Save five lines in buffer x?
- Read (import) the date string into your file?
- List your current directory?
- Create an abbreviation?
- Remove an abbreviation?
- Read another file
- Write (save) a file without quitting the vi editor?
- Delete a word?