CIT050 Index > Assignment: vim (1)

Assignment: vim (1)

The most up to date version of this assignment is at Moodle.

Read everything before doing anything!

First: if you don’t have the vim cheat sheet, download it now (PDF format).

Parts one and two are for your practice; I could look at the files afterward, but I would have no idea if you had done the correct commands! That doesn’t mean you should just skip those parts–the practice will help you for the questions at the end.

Part One

Do the tutorial on pages 151 through 158.

Part Two

Do the following:

  1. Copy ~linux199/lincoln.txt to your home directory. It is also available from the resources for this assignment if you ware working on a local Linux machine.

  2. Copy ~linux199/preamble.txt to your home directory. It is also available from the resources for this assignment if you are working on a local Linux machine.

    Note: both these files have errors in them; you will be correcting them in the next assignment.

  3. Type vim lincoln.txt to start editing the file.

  4. Open a second shell window (or another ssh session via PuTTy) and type vim lincoln.txt to see what happens if you try opening a locked file. (Use Q to quit out of the error message.)

  5. Close the second shell window.

  6. If you do not have line numbers displayed, type : (colon) to enter last line mode and then type set nu to turn on line numbers. (nu is the abbreviation for number).

  7. Split the editing window by pressing CTRL-W and then s

  8. Your cursor will be in the top half of the screen. Move it to the bottom half by pressing CTRL-W twice.

  9. Type :vi preamble.txt to edit the other file in the lower window.

  10. Press CTRL-W twice to go back to the top window, then CTRL-W twice more to return to the bottom window.

  11. Make sure you are in the bottom window, and press CTRL-W and then K (it must be a capital K) to move the bottom window to the top.

  12. In the top window, press CTRL-W and then J (it must be a capital J) to move the top window to the bottom.

  13. Press CTRL-Wuntil you are in the preamble.txt window, then press ZZ to close that window (it will also write the file).

  14. Try using the ) and ( keys to move forward and backward one sentence at a time. Notice what vim thinks is a sentence.

  15. Use the } and { keys to move forward and backward one paragraph at a time.

  16. Press the w key once to move forward one word. Now type 5w to move forward five words.

  17. Press b to move backward one word, then 5b to move backwards five words.

  18. Move the cursor to the start of the word war in line four, and press w to move forward one word.

  19. Move the cursor back to the start of the word war in line four, and press W (capital W) to move forward one word. Notice how the definition of a “word” is different.

  20. Type fh to find the next occurrence of an h ; it should be in the word whether

  21. Press CTRL-F and CTRL-B to move backward and forward a page at a time. Then press CTRL-D and CTRL-U to move up and down a half page at a time. Make sure you end up at the beginning of the file.

  22. In the next steps, if you find you have made a mistake, get to command mode by pressing ESC, and then press u to undo commands.

    Move the cursor to the space after the word Gettys on line one, and press ito enter insert mode. Notice the word --- INSERT --- at the lower left of the screen.

  23. Type burg and notice where the letters start inserting. press ESC to exit from insert mode and return to command mode.

  24. Type I to enter insert mode again. Notice that you start inserting at the beginning of the line. Enter Th and press ESC to return to command mode.

  25. Type o (lowercase letter) to open a new line. You will be in insert mode. You don’t want to put anything on this blank line, so just press ESC

  26. Move the cursor to the 2 in 2006 on line three, and then press R (capital). Notice the word --- REPLACE --- at the lower left of the screen.

  27. Type 1863 and then press ESC to get out of replace mode back to command mode.

  28. Move the cursor to the beginning of the line reading please get rid of this line, then press dw to delete one word and its following blank.

  29. Now press dd to delete the entire line.

  30. Write the file back to disk and quit vim by typing :wq

When You Finish

Answer the following questions. Please use a plain text file rather than a word processor. Do notsend me a .doc file! Name the file in the form lastname_firstname_vim1.txt . Then upload the file to Moodle.

What key or keys would you use in vim to:

  1. Find the next occurrence of a comma on the current line
  2. Move the cursor backwards six words (use the most compact form possible, please)
  3. Exit from vi without saving any changes you made during a session
  4. Go to line 57 of your Work buffer
  5. Append text to the end of the current line
  6. Write the contents of the Work buffer to disk and exit vim
  7. Write the contents of the Work buffer to disk and exit vim (use a different method than the previous question)