This is an introduction to vi, a text editor that is available on almost all Unix machines. This is what you use to create a file or to change the contents of a file.
To start up vi, use the command 'vi filename', where filename is the name of the file that you want to change. If you want to create a new file, you can just say 'vi newfilename', where newfilename is the name that you want to give the file.
The tricky part about vi is that it has two modes, insert mode and command mode. When you are in insert mode, all you can do is type text, which will go directly into the file wherever your cursor is. When you are in command mode, you can do everything else, including moving the cursor, searching, and setting options.
To move from insert mode to command mode, use the [ESC] key. If you forget to do this and end up with a ':wq' or something else that you don't want at the end of your line, just backspace over the characters that you don't want, then hit [ESC]. If you hit [ESC] when you are already in command mode, the terminal will beep at you, but it won't do anything to your file. When in doubt, hit [ESC].
To move from command mode to insert mode, use the i, a, o, or O command as described below. There are a few others, but those are the most common.
To use the following commands, you must be in command mode:
A handy thing about these commands is that you can type a number first, and the editor will do the command that many times. For instance, h moves the cursor one character to the left, and 12h moves the cursor twelve characters to the left. You shouldn't see the number or command that you type, by the way. If you do, you are in insert mode; you should backspace over the number and press the [ESC] key, then try again.
|
h - moves cursor one
character to the left |
|
x - deletes the character
the cursor is on |
d followed by a cursor movement command deletes that much text. For instance, w moves the cursor forward a word, and dw deletes to the end of the word. The 5h command moves the cursor five characters to the left, and the d5h command deletes five characters to the left.
These commands may seem a little confusing at first. The i command means that everything you type until you hit [ESC] will be inserted to the left of the cursor. In other words, this command leaves you in insert mode with the insertion point to the left of where the cursor was when you hit 'i.'
|
i - inserts text to the left
of the cursor (leaves you in insert mode) |
When you hit the colon (:), you will see it at the bottom of the screen (unless you are still in insert mode, in which case you should back up over it and press [ESC], then try again). You will see anything you type after the colon at the bottom of the screen. After commands that use a colon, you have to hit the key.
|
:q! - exits without saving
changes |
(These are useful for programmers)
|
^g - shows what line you are on at the bottom of the |
Copyright © [- SroNey / JohN -]. All rights reserved