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.
Do the tutorial on pages 151 through 158.
Do the following:
Download lincoln.txt and
save it in your home directory. If you are running an ssh
session to the server, copy ~linux199/lincoln.txt to your
home directory.
Download preamble.txt and
save it in your home directory. If you are running an ssh
session to the server, copy ~linux199/preamble.txt to your
home directory.
Note: both these files have errors in them; you will be correcting them in the next assignment.
Type vim lincoln.txt to start editing the file.
Open a second shell window (or another
ssh session) 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.)
Close the second shell window.
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).
Split the editing window by pressing CTRL-W and then s
Your cursor will be in the top half of the screen. Move it to the bottom half by pressing CTRL-W twice.
Type :vi preamble.txt to edit the other file in the lower window.
Press CTRL-W twice to go back to the top window, then CTRL-W twice more to return to the bottom window.
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.
In the top window, press CTRL-W and then J (it must be a capital J) to move the top window to the bottom.
Press CTRL-W until you are in the preamble.txt window, then press ZZ to close that window (it will also write the file).
Try using the ) and ( keys to move forward
and backward one sentence at a time. Notice what vim thinks
is a sentence.
Use the } and { keys to move forward and backward one paragraph at a time.
Press the w key once to move forward one word. Now type 5w to move forward five words.
Press b to move backward one word, then 5b to move backwards five words.
Move the cursor to the start of the word war in line four, and press w to move forward one word.
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.
Type fh to find the next occurrence of an h; it should be in the word whether
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.
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 i to enter insert mode. Notice the word --- INSERT --- at the lower left of the screen.
Type burg and notice where the letters start inserting. press ESC to exit from insert mode and return to command mode.
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.
Type o (lowercase) 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
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.
Type 1863 and then press ESC to get out of replace mode back to command mode.
Move the cursor to the beginning of the line reading please get rid of this line, and press dw to delete one word and its following blank.
Now press dd to delete the entire line.
Write the file back to disk and quit vim by typing
:wq
Answer the following questions. Please use a plain text file rather than a word processor. Do not send 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: