
How to start up vi
There are several ways to get into the A editor. A few are listed below. These are to be typed at a UNIX
prompt.
| vi | Edit a new file (the file has no name yet) |
| vi file | edit file (where file is a file name) |
| vi -r file | Edit last saved version of file after a system or editor crash |
Once you are in vi, you will need to know about its various modes.
vi Modes
There are four basic modes in vi:
| command mode | the default mode; allows you to enter vi commands |
| insert mode | this mode allows you to insert text |
| edit mode | this mode allows you to use line editing commands |
| shell escape mode | this mode allows you to execute UNIX commands |
Cursor movement
| arrow keys | to move up, down, left, and right (these work most times |
| k, j, h, I | to move up, down, left, and right respectively (these work times) |
| $ | move to the end of the line |
| 0 | move to beginning of the line |
| ctrl-u, ctrl-d | scroll up, down half a screen |
| ctrl-f, ctrl-b | scroll up, down a full screen |
Insert
All of the following commands put you in Insert Mode. To exit Insert Mode, hit ESC.
| i | insert text at cursor location |
| a | append text to the right of the cursor |
| A | append text to the end of the current line |
| o,0 | start a new line above, below the current line |
Delete
| dd | delete the current line |
| x | delete the character at the cursor |
Undo
| u | undo the last command |
Search
| / | Search forward for search string |
| ? | Search backward for search string |
For example, if you wanted to search for the word "Monday," you would type:
/Monday
or
?Monday
depending on which direction you wanted to search in. Please note that searching is case sensitive.
Misc.
| ctrl-I | Refresh the screen |
Saving and Exiting
| :w | save file with current file name (if no name exists you will have to use the next command) |
| :w file | save the file using file for the name |
| :wq | save file and exit vi |
| :q | exit vi (you may be prompted if changes have been made since last save) |
| :q! | exit vi without saving any changes since the last save |
There is more...
Remember, these are not all the commands vi has to offer. There are many more. However, they should be plenty to get started.
|
|
Last Updated: Wednesday, February 02, 2000 08:50:17