Академический Документы
Профессиональный Документы
Культура Документы
The default editor that comes with the UNIX operating system is called vi (visual editor).
Alternate editors for UNIX environments include pico and emacs, a product of GNU.
The UNIX vi editor is a full screen editor and has two modes of operation:
Command mode
This is the default when you enter vi. In command mode, most letters, or short sequences
of letters, that you type will be interpreted as commands, without explicitly pressing
Enter. If you press Esc when you're in command mode, your terminal will beep at you.
This is a very good way to tell when you're in command mode.
Insert mode
In insert mode, whatever you type is inserted in the file at the cursor position. Type a
(lowercase letter a, for append) to enter insert mode from command mode; press Esc to
end insert mode, and return to command mode.
Line mode
Use line mode to enter line oriented commands. To enter line mode from command
mode, type a colon ( : ). Your cursor moves to the bottom of the screen, by a colon
prompt. Type a line mode command, then press Enter. Any sensible command from the
Unix line editor ex will work, and a few are good to know about. These commands are
indicated in this handout by a colon in front of the command. Each time you use a line
mode command, you must type a colon to enter line mode, then type the command by the
colon prompt at the bottom of the screen, then press Enter when you finish typing the
command. (The search commands starting with / and ? work similarly
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 <Esc> (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
1
Commands in Vi editor
write all lines from the entire current file into the file
:w! newfile
'newfile', overwriting any existing newfile
G end of file
2
e end of next word
the matching (, ), [, ], {, or }
% (Press % with your cursor on one of these characters to
move your cursor its mate.)
Inserting Text
Type: To:
Deleting Text
3
Type: To:
dd delete line; 5dd deletes ... well you get the idea!
join current line with line that follows (press Enter in insert
J
mode to split line)
Note: dd or any other delete will save a copy of the deleted string in
4
the same general buffer. Therefore a cut and paste can be done with dd
and p, rather than copy and paste with yy and p. But make sure not to
overwrite the buffer with some other yank or delete command before
you have a chance to paste.
Miscellaneous Commands
Type: To: