Problem

In this hands-on project, you create and edit text files using the vi editor. 1. Switch...

In this hands-on project, you create and edit text files using the vi editor.

1. Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and log in to the terminal using the user name of root and the password of secret.

2. At the command prompt, type pwd, press Enter, and ensure that /root is displayed, showing that you are in the root user’s home folder. At the command prompt, type vi sample1 and press Enter to open the vi editor and create a new text file called sample1. Notice that this name appears at the bottom of the screen along with the indication that it is a new file.

3. At the command prompt, type My letter and press Enter. Why was nothing displayed on the screen? To switch from command mode to insert mode to allow the typing of text, press i. Notice that the word “Insert” appears at the bottom of the screen. Next, type My letter and notice that this text is displayed on the screen. What types of tasks can be accomplished in insert mode?

4. Press Esc. Did the cursor move? What mode are you in now? Press two times until the cursor is under the last “t” in “letter.” Press the x key. What happened? Next, type i to enter insert mode and type the letter h. Did the letter “h” get inserted before or after the cursor?

5. Press Esc to switch back to command mode and then move your cursor to the end of the line. Next, type the letter “o” to open a line underneath the current line and enter insert mode.

6. Type the following:

It might look like I am doing nothing, but at the cellular level I can assure you that I am quite busy.

Notice that the line wraps to the next line partway through the sentence. Though displayed over two lines on the screen, this sentence is treated as one continuous line of text in vi. Press Esc to return to command mode, and then press ↑. Where does the cursor move? Use the cursor keys to navigate to the letter “l” at the beginning of the word “level” and press the i key to enter insert mode. Press Enter while in insert mode. Next, press Esc to return to command mode and then press ↑. Where does the cursor move?

7. Type dd three times to delete all lines in the file.

8. Type i to enter insert mode, and then type:

Hi there, I hope this day finds you well.

and press Enter. Press Enter again. Type:

Unfortunately we were not able to make it to your dining

and press Enter. Type:

room this year while vacationing in Algonquin Park – I

and press Enter. Type:

especially wished to see the model of the Highland Inn

and press Enter. Type:

and the train station in the dining room.

and press Enter. Press Enter again. Type:

I have been reading on the history of Algonquin Park but

and press Enter. Type:

no where could I find a description of where the Highland

and press Enter. Type:

Inn was originally located on Cache lake.

and press Enter. Press Enter again. Type:

If it is no trouble, could you kindly let me know such that

and press Enter. Type:

I need not wait until next year when I visit your lodge?

and press Enter. Press Enter again. Type:

Regards,

and press Enter. Type:

Mackenzie Elizabeth

and press Enter. You should now have the sample letter used in this chapter on your screen. It should resemble the letter in Figure 3-4.

9. Press Esc to switch to command mode. Next, press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen. At this prompt, type w and press Enter to save the changes you have made to the file. What is displayed at the bottom of the file when you are finished?

10. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type q, and then press Enter to exit the vi editor.

11. At the command prompt, type ls and press Enter to view the contents of your current directory. Notice that there is now a file called sample1 listed.

12. Next, type file sample1 and press Enter. What type of file is sample1? At the command prompt, type cat sample1 and press Enter.

13. At the command prompt, type vi sample1 and press Enter to open the letter again in the vi editor. What is displayed at the bottom of the screen? How does this compare with Step 9?

14. Press the F1 key to display a help file for vi and its commands. Use the Page Down and Page Up keys to navigate the help file. When finished, press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type q, and then press Enter to exit the Help screen.

15. Use the cursor keys to navigate to the bottom of the document. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type !date, and press Enter. The current system date and time appear at the bottom of the screen. As indicated, press Enter to return to the document. Press the Shift and ; keys simultaneously again to open the : prompt at the bottom of the screen again, type r !date, and press Enter. What happened and why?

16. Use the cursor keys to position your cursor on the line in the document that displays the current date and time, and type yy to copy it to the buffer in memory. Next, use the cursor keys to position your cursor on the first line in the document, and type P (capitalized) to paste the contents of the memory buffer above your current line. Does the original line remain at the bottom of the document?

17. Use the cursor keys to position your cursor on the line at the end of the document that displays the current date and time, and type dd to delete it.

18. Use the cursor keys to position your cursor on the “t” in the word “there” on the second line of the file that reads Hi there, I hope this day finds you well., type dw to delete the word. Next, type i to enter insert mode, type the word Bob, and then press Esc to switch back to command mode.

19. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type w sample2, and press Enter. What happened and why?

20. Press i to enter insert mode, and type the word test. Next, press Esc to switch to command mode. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type q, and press Enter to quit the vi editor. Were you able to quit? Why not?

21. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type q!, and press Enter to quit the vi editor and discard any changes since the last save.

22. At the command prompt, type ls and press Enter to view the contents of your current directory. Notice that there is now a file called sample2, which was created in Step 19.

23. At the command prompt, type vi sample2 and press Enter to open the letter again in the vi editor.

24. Use the cursor keys to position your cursor on the line that reads Hi Bob, I hope this day finds you well.

25. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen, type s/Bob/Barb/g, and press Enter to change all occurrences of “Bob” to “Barb” on the current line.

26. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type 1,$ s/to/TO/g, and press Enter to change all occurrences of the word “to” to “TO” for the entire file.

27. Press the u key to undo the last function performed. What happened and why?

28. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type wq, then press Enter to save your document and quit the vi editor.

29. At the command prompt, type vi sample3 and press Enter to open a new file called sample3 in the vi editor. Type i to enter insert mode. Next, type P.S. How were the flies this year? Press the Esc key when finished.

30. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type wq, then press Enter to save your document and quit the vi editor.

31. At the command prompt, type vi sample1, press Enter to open the file sample1 again, and use the cursor keys to position your cursor on the line that reads “Mackenzie Elizabeth.”

32. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type r sample3, and press Enter to insert the contents of the file sample3 below your current line.

33. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen, type s/flies/flies and bears/g, and press Enter. What happened and why?

34. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type set number, and press Enter to turn on line numbering.

35. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type set nonumber, and press Enter to turn off line numbering.

36. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type set all, and press Enter to view all vi parameters. Press Enter to advance through the list and press q when finished to return to the vi editor.

37. Press the Shift and ; keys simultaneously to open the : prompt at the bottom of the screen again, type wq, and press Enter to save your document and quit the vi editor.

38. Type exit and press Enter to log out of your shell.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search