vi is a full screen editor, which most people either love or hate. It has a command mode and an input mode similar to ed, but is much easier to use as it is not line oriented, but character oriented. The cursor keys are fully usable, so it is much more intuitive.
To start editing a file we just type vi followed by the filename we want to edit (eg. vi my_file). The following screen will appear:
~ ~ ~ ~ ~ ~ "my_file" [New file]
The cursor will be in the top left hand corner. As with ed there are commands for inserting ( i) and appending ( a) text. If we insert some new text, we enter the input mode by typing i and return to the command mode by typing the ESC key.
Hello world. How are you? ~ ~ ~ ~ ~ "my_file" [New file]
We can now use the cursor keys to move around the text. To delete a character we can type x. To delete a whole line we can type dd. To search for a string we can type / followed by the expression to search for.
vi also has a subcommand mode, which covers all file functions needed. To issue one of the subcommands we first have to enter the subcommand mode by typing :. A colon will appear on the last line of the screen and we can now enter subcommands. The :w command write the text to the original file. If we append a file name (leaving a space between w and the name), we can write the text to a different file. To start editing a new file we use the :e command followed by a file name. To quit from vi we use the :q command. If we want to leave vi without saving the text we use the q! command.
Hello world. How are you? ~ ~ ~ ~ ~ ~ ~ ~ :w
These are the basic commands needed to use vi, for further information refer to the appendix .