undo command, the "U" (undo line) command.
The undo line command undoes all the changes made on the last line that was
edited. Typing this command twice cancels the preceding "U".
A very intelligent turtle ~
xxxx Delete very
A intelligent turtle ~
xxxxxx Delete turtle
A intelligent ~
Restore line with "U"
A very intelligent turtle ~
Undo "U" with "u"
A intelligent ~
The "U" command is a change by itself, which the "u" command undoes and CTRL-R
redoes. This might be a bit confusing. Don't worry, with "u" and CTRL-R you
can go to any of the situations you had. More about that in section |32.2|.
==============================================================================
*02.6* Other editing commands
Vim has a large number of commands to change the text. See |Q_in| and below.
Here are a few often used ones.
APPENDING
The "i" command inserts a character before the character under the cursor.
That works fine; but what happens if you want to add stuff to the end of the
line? For that you need to insert text after the cursor. This is done with
the "a" (append) command.
For example, to change the line
and that's not saying much for the turtle. ~
to
and that's not saying much for the turtle!!! ~
move the cursor over to the dot at the end of the line. Then type "x" to
delete the period. The cursor is now positioned at the end of the line on the
e in turtle. Now type >
a!!!<Esc>
to append three exclamation points after the e in turtle:
and that's not saying much for the turtle!!! ~
OPENING UP A NEW LINE
The "o" command creates a new, empty line below the cursor and puts Vim in
Insert mode. Then you can type the text for the new line.
Suppose the cursor is somewhere in the first of these two lines:
A very intelligent turtle ~
Found programming Unix a hurdle ~
If you now use the "o" command and type new text: >
oThat liked using Vim<Esc>
The result is:
A very intelligent turtle ~
That liked using Vim ~
Found programming Unix a hurdle ~
The "O" command (uppercase) opens a line above the cursor.
USING A COUNT
Suppose you want to move up nine lines. You can type "kkkkkkkkk" or you can
enter the command "9k". In fact, you can precede many commands with a number.
Earlier in this chapter, for instance, you added three exclamation points to
the end of a line by typing "a!!!<Esc>". Another way to do this is to use the
command "3a!<Esc>". The count of 3 tells the command that follows to triple
its effect. Similarly, to delete three characters, use the command "3x". The
count always comes before the command it applies to.
==============================================================================
*02.7* Getting out
To exit, use the "ZZ" command. This command writes the file and exits.
Note:
Unlike many other editors, Vim does not automatically make a backup
file. If you type "ZZ", your changes are committed and there's no
turning back. You can configure the Vim editor to produce backup
files; see |07.4|.
DISCARDING CHANGES
Sometimes you will make a sequence of changes and suddenly realize you were
better off before you started. Not to worry; Vim has a
quit-and-throw-things-away command. It is: >
:q!
Don't forget to press <Enter> to finish the command.
For those of you interested in the details, the three parts of this command
are the colon (:), which enters Command-line mode; the q command, which tells
the editor to quit; and the override command modifier (!).
The override command modifier is needed because Vim is reluctant to throw
away changes. If you were to just type ":q", Vim would display an error
message and refuse to exit:
E37: No write since last change (use ! to override) ~
By specifying the override, you are in effect telling Vim, "I know that what
I'm doing looks stupid, but I really want to do this."
If you want to continue editing with Vim: The ":e!" command reloads the
original version of the file.
==============================================================================