How to Use Vi Editor
 
Useful VI Commands

 Moving Around Within Text in Command Mode

 Inserting Text


All of these commands will put you in insert or append mode. Enter the text and then press escape to get back into command mode.

Deleting Text

Note: all the commands above store the deleted text in a temporary buffer. The contents of the buffer can be retrieved back into the file using the P and p commands described in the ``moving text" section below.

Moving Text

You would use the yy and p commands when wanting to copy text from one part of the file to another. You would use the dd and p commands when you want to actually move text from one part of the file to another.

Changing Text

Saving and Quitting

You should use the :w command often to save your file when you are working on it. This will help protect you in the event of a system failure. This method will also allow you to save code in one window before compiling the file in another window. If there is an error, you can make changes and save with the :w command in the code window without having to quit vi repeatedly in order to compile. Then you can compile again in the other window.

Also, you will generally use :wq when you wish to end your vi session, saving all changes you made to the file.