vi is a Visual Editor, which is where vi gets its name. Visual editors are ones that let you see the document that you are editing as you edit it. Almost all editors used today are visual editors, such as Microsoft Word and pico. Examples of non-visual editors are sed, ex, ed, and edlin (the last one being the editor shipped with DOS until relatively recently.) vi was written by William Joy as part of the bsd distribution of Unix. It was later used by AT&T, and has been standard Unix
The vi editor has two main modes of editing, Command Mode and Insert Mode. The command mode is used to issue commands to vi that let you edit the text, search and replace, and get into insert mode, to name a few functions. Once you are in insert mode, you can type all the text that you want. When you are finished with what you are inserting, press the ESC key to take you back to the command mode.
To invoke vi, simply type vi filename to open the vi editor with your filename in it. If the filename does not exist, vi will create a new file when you save your changes. You can also simply type vi and begin creating your file. You can then use the commands below to edit and save your file as needed.
Below is a list of some basic commands that can be used when you are in command mode. This list is meant as a quick reference and not as an detailed description of what these commands do. As always, the best way to learn something is to practice it.
||Insert text after the cursor.
||Insert text before the cursor.
||Open a new line below the line your cursor is currently on.
||Insert text at the end of the line.
||Insert text at the beginning of the line.
||Open a new line above the line your cursor is currently on.
||Delete the character beneath the cursor.
||Move your cursor to the left by one character.
||Move your cursor to the right by one character.
||Move your cursor up by one line.
||Move your cursor down by one line.
||Move to the end of the line.
||Move to the beginning of the line.
||Move forward one word and place the cursor on the first character of that word.
||Move backward one word and place the cursor on the first character of that word.
||Go to the end of the file.
||Go to line 1 of the file.
||Report on the current line number that the cursor if on as well as the number of total lines in the file.
||Delete the current line.
||Change word. That is, change the characters from where your cursor is to the next space or punctuation.
||Change letter. Change the character that your cursor is on.
||Copy the line that the cursor if currently on.
||Place the contents of either a deleted line or a copied line on the line immediately following the one your cursor is currently on.
||Undo the last change.
||Save changes. The filename is optional and is only used to specify the name of the file that you would like to save your work as.
||Save changes and quit. Again, the filename is optional.
||Save changes and quit.
||Quit without saving changes.
||Search for next occurrence of string in the file.
||Repeat the last search
||Repeat the last insert function.
If you feel up to seeing how much of this you retained, then take our VI Quiz.