Title: The vi editor
1The vi editor
- CS240 Computer Science II
2The three modes of vi Editor
3Fucntions of the three mode in vi
- Input mode allows text such as source code to be
entered. - Command mode allows various commands to be
entered for text editing and other purposes.
Several commands such as insert, append, open,
replace, and change that are issued in the
command mode will take you to the input mode. - Last-line mode all commands that start with a
colon puts vi in the last-line mode. - Note all text entered is temporarily kept in a
buffer until permanently saved to disk.
4Starting vi
Command Function
vi filename Create/edit filename starting a line 1.
vi n filename Edit filename starting a line n.
vi filename Edit filename starting last line.
vi -r filename Recover filename after a system crash.
5Adding text filename from command to input mode
must press Escape key to return to command mode
Command Insert text
i Before the cursor.
I Before first non-blank character on line.
a After the cursor.
A At the end of the line.
o Open a line below the current line.
O Open a line above the current line.
6Some moving cursors in the command mode
Command Cursor movement
Space, I, or ? Space to the right
H or ? Space to the left
w or W Word to the right or blank-delimited word to the right.
b or B Word to the left or blank-delimited word to the left.
End of the line.
0 Beginning of the line.
7Miscellaneous Commands
Command Effect
w filename Store contents of buffer to filename.
q Quite vi.
q! Quite vi with saving contents of buffer.
Change upper case to lower case and vice versa.
ZZ Store content of buffer and quit vi.
f or CtrlG Displays the filename, the status,the current line number, the number of lines in the buffer, etc.
8viewing different parts of the buffer in the
command mode
Command Cursor movement
Ctrl D Down (forward) one-half screen.
Ctrl U Up (backward) one-half screen.
Ctrl F Down (forward) one full screen.
Ctrl B Up (backward) one-full screen.
nG To line n or to the last line if without n.
H To the top of the screen.
M To the middle of the screen.
L To the bottom of the scren.
9Customizing the vi environment the set command
- In the command mode type set followed by a
parameter listed below and press enter key. - all lists a complete list of parameters and
their current status. - atuoindent (or ai) creates tab stops CtrlT tabs
right and Ctrl_D tabs left. noautoindent or noai
turns off autoindent feature. - shiftwidthnn sets the spacing (characters)
between tab stops - number to display line numbers nonumber remove
line numbers. - wrapmarginnn, where nn is arbitray positive
integer representing characters after which
wrap-around takes place. - showmode displays the mode type noshowmode
removes the display. - Note that the parameters can be permanently set
in a users startup file .profile With Bourne or
Korn shell, or .login with C shell. The
parameters may also be set in a .exrc file.