|
作者 0/brd/unix/Q/A001001Q
标题 vi 使用说明 简易版
时间 (bbs.cs.nthu.edu.tw) Tue Aug 16 10:19:53 2005
───────────────────────────────────────
_V_I_ _ _Q_u_i_c_k_ _ _R_e_f_r_e_n_c_e
Entering and Leaving _v_i
% vi _n_a_m_e edit _n_a_m_e at top
% vi +n _n_a_m_e ... at line n
% vi + _n_a_m_e ... at end
% vi -r list saved files
% vi -r _n_a_m_e recover file _n_a_m_e
% vi _n_a_m_e ... edit first; rest via :n
% vi -t tag start at tag
% vi +/_p_a_t _n_a_m_e search for _p_a_t
% view _n_a_m_e read only mode
ZZ exit from _v_i, saving changes
CTRL-Z stop _v_i for later resumption
The Display
Last line Error messages, echoing input to :/? and !,
feedback about i/o and large changes
@lines On screen only, not in file.
-lines Lines past end of file.
CTRL-x Control character, DEL is delete.
tabs Expand to space, cursor at last.
Vi Modes
Commands Normal and initial state. Others return
here. ESC (escape) cancels partial command.
Insert Entered by a i A I o O c C s S R. Arbitrary
text then terminates with ESC character, or
abnormally with interrupt.
Last line Reading input for:/? or !; terminate with
ESC or CR to execute, interrupt to cancel.
Counts Before vi Commands
line/column number z G |
scroll amount CTRL-D CTRL-U
replicate insert a i A I
repeat effect most rest
Simple Commands
dw delete a word
de ... leaving punctuation
dd delete a line
3dd ... 3 lines
i_t_e_x_tESC insert _t_e_x_t abc
cw_n_e_wESC change word to _n_e_w
ea_sESC pluralize word
xp transpose characters
Interrupting, Canceling
ESC end insert or incomplete cmd
CTRL-C interrupt (or DEL)
CTRL-L refresh screen if scrambled
File Manipulation
:w write back changes
:wq write and quit
:q quit
:q! quit, discard changes
:e _n_a_m_e edit file _n_a_m_e
;e! reedit, discard changes
:e + _n_a_m_e edit, starting at end
:e +n edit starting at line n
:e # edit alternate file
CTRL-^ synonym for :e #
:r _n_a_m_e read file _n_a_m_e
:w _n_a_m_e write file _n_a_m_e
:w! _n_a_m_e overwrite file _n_a_m_e
:sh run shell, then return
:!_c_m_d run _c_m_d, then return
:n edit next file in arglist
:n _a_r_g_s specify new arglist
:f show current file and line
CTRL-G synonym for :f
:ta _t_a_g to tag file entry _t_a_g
CTRL-] :ta, following word is tag
Positioning within File
CTRL-F forward screenfull
CTRL-B backward screenfull
CTRL-D scroll down half screen
CTRL-D scroll up half screen
nG goto the n'th line (end if n drops)
/_p_a_t next line matching _p_a_t
?_p_a_t previous line matching _p_a_t
n repeat last / or ?
N reverse last / or ?
/_p_a_t/+_n _n'th line after _p_a_t
?_p_a_t?-_n _n'th line before _p_a_t
]] next section/function
[[ previous section/function
% find matching ( ) { or }
Adjusting the Screen
CTRL-L clear and redraw
CTRL-R retype, eliminate @ lines
zCR redraw, current at window top
z- ...at bottom
z. ...at center
/_p_a_t/z- _p_a_t line at bottom
z_n. use _n line window
CTRL-E scroll window down 1 line
CTRL-Y scroll window up 1 line
Marking and Returning
`` previous context
'' ... at first non-white in line
m_x mark position with letter _x
`_x to mark _x
'_x ... at first non-white in line
Line Positioning
H home window line
L last window line
M middle window
+ next line, at first non-white
- previous line, at first non-white
CR return, same as +
j next line, same column
k previous line, same column
Character Positioning
^ first non-blank
0 beginning of line
$ end of line
h forward
l backwards
CTRL-H same as l
space same as h
f_x find _x forward
F_x f backward
t_x upto _x forward
T_x back upto _x
; repeat last f F t or T
, inverse of ;
| to specified column
% find matching ( { ) or }
Word, Sentences, paragraphs
w word forward
b back word
e end of word
) to next sentence
} to next paragraph
( back sentence
{ back paragraph
W blank delimited word
B back W
E to end of W
Commands for LISP
) Forward s-expression
} ...but don't stop at atoms
( Back s-expression
{ ... but don't stop at atoms
Corrections During Insert
CTRL-H erase last character
CTRL-W erase last word
erase your erase, same as CTRL-H
kill your kill, erase input this line
\ escapes CTRL-H, your erase and kill
ESC ends insertion, back to command
CTRL-C interrupt, terminates insert
CTRL-D backtab over autoindent
CTRL-^D kill autoindent, save for next
0/CTRL-D ... but at margin next also
CTRL-V quote non-printing character
Insert and Replace
a append after cursor
i insert before
A append at end of line
I insert before first non-blank
o open line below
O open line above
r_x replace single character with _x
R replace characters
_nr_x replace _n characters with _x
Operators (double to affect lines)
d delete
c change
< left shift
> right shift
! filter through command
= indent for LISP
y yank lines to buffer
Miscellaneous Operations
C change rest of line
D delete rest of line
s substitute characters
S substitute lines
J joint lines
x delete characters
X ... before cursor
Y yank lines
Yank and Put
p put back lines
P put before
"_xp put from buffer _x
"_xy yank to buffer _x
"_xd delete into buffer _x
Undo, Redo, Retrieve
u undo last change
U restore current line
repeat last change
"_dp retrieve _d'th last delete
--
[m[1m※ 来源:.天大求实 BBS bbs.tju.edu.cn.[FROM: bbs.tju.edu.cn][m |
|