The default editor that cames with the Unix operating system is vi (others; nano,pico, emacs )
The Unix vi editor has two modes of operation:
-
-
Command mode commands which cause action to be taken on the file, and
-
Insert mode in which entered text is inserted into the file.
In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the (Escape) key turns off the Insert mode.
-
While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic.
-
NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expect.
-
-
To Start vi:
-
-
To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.
-
-
To Exit vi:
-
-
Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.
-
Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the (or ) key.
* |
:x |
quit vi, writing out modified file to file named in original invocation |
|
:wq |
quit vi, writing out modified file to file named in original invocation |
|
:q |
quit (or exit) vi |
* |
:q! |
quit vi even though latest changes have not been saved for this vi call |
So if you want to modify file, use ESC ,then wq <enter>. If you dont want to modify file, use ESC and q! <enter>.
Undoing last action:
-
Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.
-
Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step.
* |
u |
UNDO WHATEVER YOU JUST DID; a simple toggle |