The VI Editor
To move from insert mode to command mode, use the [ESC] key. If
to do this and end up with a ':wq' or something else that you don't
at the end of your line, just backspace over the characters that you don't
want, then hit [ESC]. If you hit [ESC] when you are
already in command mode,
the terminal will beep at you, but it won't do anything to your file. When
in doubt, hit [ESC].
To move from command mode to insert mode, use the i, a, o, or O command
as described below. There are a few others, but those are the most common.
To use the following commands, you must be in command mode:
A handy thing about these commands is that you can type a number first, and
the editor will do the command that many times. For instance, h moves the
cursor one character to the left, and 12h moves the cursor twelve characters
to the left. You shouldn't see the number or command that you type, by the
way. If you do, you are in insert mode; you should backspace over the number
and press the [ESC] key, then try again.
- h - moves cursor one character to the left
- j - moves cursor one line down
- k - moves cursor one line up
- l - moves cursor one character to the right
- ^f - moves cursor one screen forward
- ^d - moves cursor a half screen down
- ^b - moves cursor one screen backward
- ^u - moves cursor a half screen up
- ^ - moves cursor to the beginning of the line
- $ - moves cursor to the end of a line
- w - moves cursor one word forward, with punctuation and braces as new words
- W - moves cursor forward to the next word
- b - moves cursor one word backward, with punctuation and braces as new words
- B - moves cursor backward to the next word
- /pattern - searches for pattern and moves the cursor there
- ?pattern - searches backwards for pattern and moves the cursor there
d followed by a cursor movement command deletes that much text. For instance,
w moves the cursor forward a word, and dw deletes to the end of the word.
The 5h command moves the cursor five characters to the left, and the d5h
command deletes five characters to the left.
- x - deletes the character the cursor is on
- X - deletes the character to the left of the cursor
- dd - deletes the entire line the cursor is on
These commands may seem a little confusing at first. The i command means that
everything you type until you hit [ESC] will be inserted to the left of the
cursor. In other words, this command leaves you in insert mode with the
insertion point to the left of where the cursor was when you hit 'i.'
- i - inserts text to the left of the cursor (leaves you in insert mode)
- a - appends text to the right of the cursor (leaves you in insert mode)
- A - appends text at the end of the line (leaves you in insert mode)
- o - opens new line under the line the cursor is on (leaves you in insert mode)
- O - opens new line above the line the cursor is on (leaves you in insert mode)
How Do I Get Out Of This Thing, Anyway?
When you hit the colon (:), you will see it at the bottom of the screen (unless
you are still in insert mode, in which case you should back up over it and
press [ESC], then try again). You will see anything you type after the colon
at the bottom of the screen. After commands that use a colon, you have
to hit the key.
- :q! - exits without saving changes
- :w - write changes
- :wq - write changes, then quit
Line Number Commands
(These are useful for programmers)
- ^g - shows what line you are on at the bottom of the line
login as root
should be in
lets create a .forward file...
i to insert
enter email address you want to forward to
escape to exit from insert mode
:wq .forward to write the file out as .forward and exit
lets add a second email address to the
$ to move to end of line
a to start inserting text to the right of the cursor
enter email address
:wq to write and quit
Remove the .forward file