Exercise 3: Simple Editing

We begin with the “delete” command. As with most commands, this takes a movement parameter. Please maneuver your cursor to the word “a” on the second line of our example text. We delete this word by typing


That is, delete word. Next, please navigate to the word “fun” and delete it using only ‘w’ and “dw”. Now, delete the word “paper” using only two commands, one to move to the word and a second to delete it. Are you getting the hang of moving by words?

Next, return the cursor to the first letter of the first “do” word in the line. Though we won’t take this route, how could we fix this typo using a scaler version of “cw”? Instead, we will perform a similar operation and delete all four words with the command


<Aside> 4dw literally means (delete word) four times; and equivalent statement would be d4w delete (4 words). In ViM, there are several different methods of performing the same operation; you will learn which method feels right for you.</Aside>Wait! We have made a mistake! What can we do? Of course, ViM has a solution, the Undo command (‘u’). Please revert the text to include two “do not”s with the Undo command.

This line still is not correct, however, so let’s fix it by deleting the two words “do not”. How could we do that with one command? This version looks a little better, but I’m not sure. Try undo-ing again. Actually, the version with only one “do not” looks correct, so let’s redo our undo with the Redo command (Ctrl-r). Whew. Much better.

Let’s move our cursor to the beginning of the “sOMEBODY” line. Type the ‘End’ key, followed by the ‘Home’ key to return to the start of the line we’ve been working on. ‘End’ and ‘Home’ were not standard when Vi (a predecessor to ViM) was created, so an alternative (and much more widely used) version of the end-of-line command is the ‘$’ key, while the start-of-line command is ‘0’. Try it now. As ‘$’ is a motion, we can combine it with the delete and change commands. Try deleting everything after the first period.

Our next objective is to learn some single character commands. We begin with deletion of one character with a single stroke (d-<right arrow> has too many key strokes, after all). Move your cursor to the second d in “jumpedd” on the first line. Type


This should delete the single character. Fix “ovverr” through the same method. The ‘x’ command is also a form of movement, so we can use it to delete several character at a time if needed. For example, try to delete two ms from “mmmoon” with the


command. Try to get rid of the os as well. How can we undo this mistake?

We can also modify the case for a given character with the ‘~’ (tilda) command. Move your cursor to “sOMEBODY” and press


Notice that tilda not only inverts the case, but also moves the cursor forward, hence we can keep pressing tilda until “sOMEBODY” is fixed. Please move the cursor to “THIS LINE” using only word movement. How could we fix the case of “THIS LINE” using only one command (two key strokes)? <Hint> Both ‘x’ and ‘~’ operate immediately on exactly one character. Think of the 2x example and test what the ‘~’ command does to a space</Hint>

Commandd[movement]Delete movement and add them to the
buffer (described in section 5)
Ex. d4) deletes 4 sentences
Commandxd[movement]Equivalent to dxmovement
CommanduUndo previous changes
(i.e. move back through undo history)
Command<Ctrl>-rRedo previously undone changes
(i.e. move forward through undo history)
Command0Equivalent to <Home>
Command$Equivalent to <End>
CommandxxDelete x characters and add them to
the buffer (described in section 5)
Ex. 5x deletes 5 characters
Commandx~Changes the case of the next x letters,
non-letters (whitespace, numbers, etc.)
Ex. 15~ reverses the case of the next
15 letters
© C.M. Lubinski 2008-2021