next up previous contents
Next: Getting Around with the Up: The Woodnotes Guide to Previous: Files (Opening, Saving, etc.)   Contents

General Editing of Text

Here, too, an adequate mastery of a few common commands makes basic text entry a lot more efficient and allows you to make edits on the fly without stopping to take your hands off the keyboard. They all require the control key, because these commands are expected to be entered while you are still in insert mode.

The most important is control-w, which deletes the most recent word and permits you to keep typing. Similarly, control-r x inserts the contents of register x at the cursor.5

In command mode, use the following to speed up editing and in particular, to take advantage of commands that allow you to, with one keystroke, position the cursor, erase text, and begin editing.

Figure 2: General Editing Commands
\begin{figure}\begin{tabular}{ll}
\par
Function & Key \ \hline
Insert before, a...
...e cursor & o,O \\
Join this line to the next & j \\
\end{tabular}
\end{figure}

A few examples will make the benefit clear. As an author I frequently begin a sentence and then decide halfway through that I am not pleased with what I have begun to write. A simple c( instructs Vim to change (erase and prepare for replacement of) everything to the beginning of that sentence. I can just as easily type c7b to change the last 7 words. If I've edited something mid-paragraph and am ready to now place the cursor at the end of the paragraph and keep writing, it's as simple as typing a capital A. It's also quick to select some text using visual mode, press d to delete it, and continue.

Note that where delete and insert commands are concerned, pressing the .key (the period) instructs Vim to repeat the last command. If you type dw (delete word) and then 3. the second command will delete 3 more words. Be careful!

One last word about editing. Vim remembers up to 100 of your last commands6 This allows you a lot of flexibility with the undo command. Press u in command mode to undo your last command, and keep pressing it until you are satisfied. Control-r works in the opposite direction, redoing what you've just undone.


next up previous contents
Next: Getting Around with the Up: The Woodnotes Guide to Previous: Files (Opening, Saving, etc.)   Contents
Randall Wood 2009-08-04