Question: Do it in centOS linux opereting system and login to Student account. The vi Editor Login to your Student account and do the following: You
Do it in centOS linux opereting system and login to Student account.
The vi Editor
Login to your Student account and do the following:
You will create two files in this lab and edit a third, all using vi.
1. Enter vi. You will see a buffer that consists of lines that start with a ~ and some welcome information. The cursors location is listed in the bottom right. The word All indicates that the whole file is being displayed. You are in command mode. To enter text, you must enter either insert or replace mode. Type I (insert mode). What appears at the bottom of the window? Enter the following, pressing
Colorado
Kentucky
Indiana
Minnesota
North Carolina
Ohio
Texas
Type
2. Experiment with moving around the document. First, try using: h, j, k, l (lower case L), G, 1G, $, 0 and nG where n is a line number. a. Type 1G. Where did your cursor move to? From the top of the file, what keystrokes can you enter to move to the end of Indiana? To the beginning of Ohio? The end of Texas? Attempt to solve these with the fewest keystrokes possible.
b. Move to the bottom of the file, enter insert mode. Enter Georgia and return to command mode. How did you accomplish this entire step?
c. Lets explore how to edit what you already have in place. Move to the beginning of North Carolina. Change North to South using the replace mode. Enter replace mode by typing R. Type Sou to overwrite Nor. You dont have to type the th because its already there. Press
d. Move the cursor back to the beginning of this line. Type r. This replace mode allows you to change only one letter. Change the N to an S. You do not need to change the next letter, o, it is correct. Explain how to move the cursor and change the r in North to the u in South. Save the file by typing :w
e. Northern Kentucky has decided to form its own state so we want to add North Kentucky to the list. We will copy, paste and edit Kentucky. Move the cursor to any point in the word Kentucky. How did you get the cursor there? Type yy. This copies the entire line of the cursor into a buffer. Type p to paste the copied line into a new line above the current line (P places it below the current line since we are copying and pasting the same line, it doesnt matter which we use, p or P). Move to the beginning of the new line. Enter insert mode and type North (North and a space). Exit insert mode.
3. We will wrap up this file by looking at other vi features. a. You can enter commands by typing :command, one of which is sort. Type :sort
b. Using copy and paste, copy New Mexico and paste it and change the second occurrence to New York. Explain how you accomplished this in a step-by-step description.
c. Move to New York. Move the cursor after the w in New (it can either be on the blank or on the Y in York). Type D. What happens? Replace York with Jersey (the line is now New Jersey). Since New Mexico and New Jersey are in the wrong positions, sort the file again. How did you accomplish the sort? Save your file. How did you do this? [Hint: Try to save forcefully ]
d. Move to the top of the file. To search for string, type /string
4. From Linux, type cp ~zappaf/ZAPPA/overnite.sensation . to copy this file to Students home directory. Now, open this file in vi. How did you do that? a. Move down to the 30th line in the file. How did you do that? The commands H, M, L, control+f, control+d, control+b, and control+u move your view in the file. Try each one. What is the difference between H, M and L? Between control+f and control+b? Between control+f and control+d?
b. Search forward for the word POODLE and count the number of occurrences found. How do you search forward after the first instance is found? How many POODLES did you find Move to the front of the line of the first occurrence of POODLE. Enter the two characters xp as a command. What does this do? Move forward to the P in POODLE and repeat xp. Move forward to the B in the word BITES. Type dw. What does this command do? Type the letter U. What did this command do?
c. Move down one line so that the cursor is on the (. Type %. What happens? Type % again. What happens?
d. Search forward for dandruff. Once on that line, type J. What happens? Type u to undo this command.
e. To repeat a command in vi, use . To repeat a command multiple types, type the command as in #command where # is a number and command is the keystroke. For instance, to delete 4 lines, you would use 4dd. The lyrics for Fifty-Fifty has 40 lines. Move the start of this song (search backward for 50). Type 40dd. What happened? The entire set of lyrics for this song should be in the buffer. Move to the bottom of the file. How did you
do this? Type o to enter insert mode, and add a two blank lines. Type
f. Search backward for the word Pair. Once there, use the command w several times. What does w appear to do? Try W. Also try each of: b, B, e, E. Summarize what each does. NOTE: try all of these on several lines that include punctuation marks.
Save this file and exit vi.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
