vi Tutorial - Part I -
I. Getting into Vi
You can start using VI or creating a new file , by the below command:
vi filename RETURN
Ex: vi config.txt
If the file is new, vi displays a column of ~ (tildes) in the first column. The blinking cursor is placed at the beginning of the file.
II. Typing In Your Text
VI has two modes
i) Insert mode
ii) Command mode
Insert Mode is the mode that you use to write/type characters to the file, and VI does not interact with what you type and just added it to the file buffer. When you are in "command mode" the keys you press cause actions like moving from place to place in your file and making changes to what you have typed. Please note that when you start vi you will be in "command mode" by default.
III. What the $!#^*& happened??!!
Undo commands:
- u — undo last command ONLY
- U — undo all changes to the current line you are working on
IV. Inserting Text
VI incorporates several methods of inserting text into a document. There are three different methods you can use while you are in COMMAND mode. Typing an 'i' (for INSERT mode) keystroke allows you to insert characters into the document at the left edge of the cursor. As mentioned above, typing the
Insert commands - These are the only commands which will allow you to enter text before the BEGINNING of a line. | ||
i | — | Inserts text to the left of the cursor. |
I | — | Inserts text at the beginning of the line, no matter where the cursor is positioned on the current line. |
Append commands - These are the only commands which will allow you to enter text AFTER the END of a line. | ||
a | — | Begins inserting after the character (append) on which the cursor is positioned. |
A | — | Begins inserting at the end of the current line, no matter where the cursor is positioned on that line. |
Open commands | ||
o | — | Begins inserting text on a new, empty line that is opened for you, below the current line. This is the only command that will allow you to insert text BELOW the LAST line of the file. |
O | — | Begins inserting text on a new, empty line that is opened for you, above the current line. This is the only command that will allow you to insert text ABOVE the FIRST line of the file. |
There are other commands that place you in INSERT mode. These commands are used to perform substitutions of text. That is, the deletion of old text and the insertion of new text, all in a single operation. These commands will be discussed later because the are actually variations on the change command.
Comments