To start writing a new file in vi, or to
view an existing vi file, enter the following command at a UNIX
prompt, replacing filename with the name of an existing file, or the
name of the new file you want to create:
vi can be in different modes, the most common being command mode and
insert mode. By default, when you start up vi, it is in command mode,
which enables you to do things like navigate around in the file, delete lines,
and so on. However, you need to be in insert mode in order to be able to
insert new text in the file.
To change between modes, press the Escape (ESC) key. If you're ever in doubt when you're editing a vi file, or if you're stuck, press the ESC key, and try issuing your command. This should help you determine if you're in command or insert mode.
To move around in the file, you can press the up or down arrow keys. The left and right arrow keys will move the cursor left or right. If you're accessing RCS from a remote connection, you might find that the arrow keys don't work.
If you press the up or down arrow key and a single character appears on each line as you go, you are in insert mode. Press the ESC key and try the arrow keys again.
If you encounter other problems, try these keys:
| Move | Key |
| up | k or |
| down | j or |
| backward | h or |
| forward | l or |
Other ways to move around include:
| Press This | For This Function |
| CTRL-b | scrolls one screen backward |
| CTRL-f | scrolls one screen forward |
| G | moves the cursor to the last line of the file |
| 1G | moves the cursor to the first line of the file |
To start entering text, type the vi command i. Do not press Enter or Return. The i that you pressed will not appear on the screen - you have just issued a command to vi, telling it that you want to insert text. Any character you type now will appear on your screen. (Also note that pressing arrow keys will cause random letters to appear.)
If you start typing, and the text you expect does not appear on the screen (perhaps nothing happens or you get single characters on several lines), you are in some mode other than insert mode. Press the ESC key, issue the insert command (press i), and resume typing. Press Return or Enter at the end of every line; the text does not automatically wrap within the UNIX window.
Press the Escape key to enter command mode. Place the cursor over the character you want to delete and press the x key.
To delete an entire word and the space after it, place the cursor on the first letter of the word and type dw for delete word. The word will disappear.
To delete an entire line, type dd.
To delete to the end of the line, type D.