vi is quite useful if you want to edit a file with a command shell.
maybe most of us are not familar of it, since we are too used of the GUI interface.
Here is some basic useage of this tool, and I will put all the original article at the bottom.
1. mode change
we as know, there are two mode of vi, edit mode and command mode.
edit mode for input, all the character in pressed on the keyboard will displayed in the editor;
command mode is for control, every character you input may have some special function, which will be particular illustrated below.
of course we can tell the mode from the indicator from the bottom of the eidtor.
a. from command to edit
'i' or 'a', change command mode to edit mode
b. from edit mode to command
use 'esc'
2. basic command
some are used so often, that I will mark it with different color.
ENTERING TEXT
a append text right of cursor
MOVING THE CURSOR
h left one space
j down one line
k up one line
l right one space
BASIC EDITING
x delete character
nx delete n characters
X delete character before cursor
dw delete word
ndw delete n words
dd delete line
ndd delete n lines
D delete characters from cursor to end of line
r replace character under cursor
cw replace a word
ncw replace n words
C change text from cursor to end of line
o insert blank line below cursor
(ready for insertion)
O insert blank line above cursor
(ready for insertion)
J join succeeding line to current cursor line
nJ join n succeeding lines to current cursor line
u undo last change
MOVING AROUND IN A FILE
ZZ save file and then quitw forward word by word
b backward word by word
$ to end of line
0 (zero) to beginning of line
H to top line of screen
M to middle line of screen
L to last line of screen
G to last line of file
1G to first line of file
<Control>f scroll forward one screen
<Control>b scroll backward one screen
<Control>d scroll down one-half screen
<Control>u scroll up one-half screen
n repeat last search in same direction
N repeat last search in opposite direction
:wq save and quit
:w save file :q! discard changes and quit file 3 search mode this is very very useful if you are reading a log file.a.press 'esc' to command mode
b.press '/' call the search input c. input the text you wan't to search.And the cursor will moves to the first occurrence of that text.
To repeat the search in a forward direction, type
nTo repeat the search in a backward direction, type
N
the origin content is from:
http://www.washington.edu/computing/unix/vi.html