|% vi filename||Edit filename with vi.|
|% view filename||Read filename with vi.|
Note: if filename does not yet exist, this first command will create it.
The vi editor has command and insert modes. Command mode is the default (this differs from most PC programs), and in it you move the pointer or cursor around the file, delete text, and save your work. In insert mode you enter text into the file. The editor always begins in command mode and returns to it after executing an insert mode command successfully. To enter insert mode, you type insert commands like i, o, I, O, cw, CW; to leave insert mode (return to command mode), hit the escape key (sometimes marked Esc, sometimes mapped onto ` [accent grave]). If at some point you are not sure of your mode or what is happening or you just like to see flashes or hear bells, you can make it a practice to be sure and hit esc-it will hurt nothing.
Figure 1.2: Movement commands in vi for different objects.
Sometimes you realize you have made changes you don't want, or you think your original had something in it your changed version doesn't and you want to go back to the original. You undo the harm of your last command with u, or undo all changes on the present line with U. If you think you may have really messed up your file, you may want to :q!, that is, quit without rewriting the file. (You can write it to a temporary file with :w temp and then quit in case you think you may have done some good.)