bhobjj
05-08-2006, 03:44 PM
Vi basic basics
Sooner or later, you will find yourself editing a file with vi.
Vi is the first full screen editor for computers. Vi is the standard editor that is installed by default on any UNIX system. Because it uses very little resources, It is very fast even on old computers and slow network connections. Vi is very powerful, with almost unlimited features. The program that is installed on your machine is probably vim. Vim stands for (Vi)mproved.
Because vi has so many features, trying to read the documentation can be like "drinking from a firehose". You can use vi as an file editor by learning a few basic commands.
The basics
Vi runs in two modes:
command mode, and insert (edit) mode.
When vi starts, it is running in command mode.
Starting vi
Start vi from the console using the following command:
$ vi
or to use vi to edit a named file:
$vi filename
Inserting text
To begin inserting text, you press Esc key, then the i key, for insert.
i
Once you have pressed i you will see the cursor change and you will see --INSERT-- in the lower left corner of the screen if you are using a newer version of vi (vim). You now can start inserting text.
Saving (writing) changes
To save changes you made to a file, you need to be in command mode. To leave insert mode and enter command mode, you press the Esc key. The cursor will change again, indicating that you have now switched to command mode. You can write (save changes) to the file that you were working on with:
:w
or
:w filename
Quitting vi
To quit vi, you need to be in command mode. To leave insert mode and enter command mode, you press the Esc key. The cursor will change again, indicating that you have
now switched to command mode. You can quit vi with:
:q
or
quit vi and save changes:
:wq
quit without saving any changes with:
:q!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At this point, you have enough information to begin using vi.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Read on for a few more basic commands.
A Few More Useful Commands:
(Remember that to enter command mode press the Esc key.)
Copy And Paste
To copy (yank) a line:
yy
To paste a line:
p
Search
/string_to_search
to search the next instance of the same string
/
Undo And Redo
undo
:u
redo
:red
undo everything
:U
Retrieve (open) The Contents of A File
:r filename
Run An External Shell Command
:! command
Help
You can access help with
:help
:q will close the help window
Vim Documentation page:
http://vimdoc.sourceforge.net/
Vim Tutorial:
$ vimtutor
Note
There are two types of commands:
External commands are preceded with a ":" internal commands are not preceded with a ":".
There are many, many more commands and features. Even the few basic commands that I have described can be elaborated upon to provide many more functions.
Sooner or later, you will find yourself editing a file with vi.
Vi is the first full screen editor for computers. Vi is the standard editor that is installed by default on any UNIX system. Because it uses very little resources, It is very fast even on old computers and slow network connections. Vi is very powerful, with almost unlimited features. The program that is installed on your machine is probably vim. Vim stands for (Vi)mproved.
Because vi has so many features, trying to read the documentation can be like "drinking from a firehose". You can use vi as an file editor by learning a few basic commands.
The basics
Vi runs in two modes:
command mode, and insert (edit) mode.
When vi starts, it is running in command mode.
Starting vi
Start vi from the console using the following command:
$ vi
or to use vi to edit a named file:
$vi filename
Inserting text
To begin inserting text, you press Esc key, then the i key, for insert.
i
Once you have pressed i you will see the cursor change and you will see --INSERT-- in the lower left corner of the screen if you are using a newer version of vi (vim). You now can start inserting text.
Saving (writing) changes
To save changes you made to a file, you need to be in command mode. To leave insert mode and enter command mode, you press the Esc key. The cursor will change again, indicating that you have now switched to command mode. You can write (save changes) to the file that you were working on with:
:w
or
:w filename
Quitting vi
To quit vi, you need to be in command mode. To leave insert mode and enter command mode, you press the Esc key. The cursor will change again, indicating that you have
now switched to command mode. You can quit vi with:
:q
or
quit vi and save changes:
:wq
quit without saving any changes with:
:q!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At this point, you have enough information to begin using vi.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Read on for a few more basic commands.
A Few More Useful Commands:
(Remember that to enter command mode press the Esc key.)
Copy And Paste
To copy (yank) a line:
yy
To paste a line:
p
Search
/string_to_search
to search the next instance of the same string
/
Undo And Redo
undo
:u
redo
:red
undo everything
:U
Retrieve (open) The Contents of A File
:r filename
Run An External Shell Command
:! command
Help
You can access help with
:help
:q will close the help window
Vim Documentation page:
http://vimdoc.sourceforge.net/
Vim Tutorial:
$ vimtutor
Note
There are two types of commands:
External commands are preceded with a ":" internal commands are not preceded with a ":".
There are many, many more commands and features. Even the few basic commands that I have described can be elaborated upon to provide many more functions.