vi Editor

Open a New File

To open a new file with a specific file name in vi, type:

vi <filename>


<filename> is replaced by the actual file name, for example hw.cpp

Editing a File

vi opens in a non-editing mode. This means it will not register any of the typed characters at first. To switch on the editing mode, press the letter "i" on the keyboard.

At this point you can begin editing your file.

Exit the Edit Mode

Once you are done editing your program, press the Escape key on the keyboard to exit the edit mode.

Save File and Continue Editing

If you are in edit mode, press Escape and type :w to save the file. Press the letter "i" to resume editing.

Save File and Exit

If you are in edit mode, press Escape and type :wq to save the file and exit the vi editor.