找回密码
 注册
查看: 739|回复: 0

vi 使用说明 稍多版

[复制链接]
发表于 2005-8-16 20:16:00 | 显示全部楼层 |阅读模式
作者  0/brd/unix/R/A001001R
标题  vi 使用说明  稍多版
时间  (bbs.cs.nthu.edu.tw) Tue Aug 16 10:22:15 2005
───────────────────────────────────────

                        VI__Quick__Refrence

Entering and Leaving vi
% vi name               edit name at top
% vi +n name            ... at line n
% vi + name             ... at end
% vi -r                 list saved files
% vi -r name            recover file name
% vi name ...           edit first; rest via :n
% vi -t tag             start at tag
% vi +/pat              name search for pat
% view name             read only mode
ZZ                      exit from vi, saving changes
CTRL-Z                  stop vi 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
itextESC                insert text abc
cwnewESC                change word to new
easESC                  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 name                 edit file name
;e!                     reedit, discard changes
:e + name               edit, starting at end
:e +n                   edit starting at line n
:e #                    edit alternate file
CTRL-^                  synonym for :e #
:r name                 read file name
:w name                 write file name
:w! name                overwrite file name
:sh                     run shell, then return
:!cmd                   run cmd, then return
:n                      edit next file in arglist
:n args                 specify new arglist
:f                      show current file and line
CTRL-G                  synonym for :f
:ta tag                 to tag file entry tag
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)
/pat                    next line matching pat
?pat                    previous line matching pat
n                       repeat last / or ?
N                       reverse last / or ?
/pat/+n                 n'th line after pat
?pat?-n                 n'th line before pat
]]                      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
/pat/z-                 pat line at bottom
zn.                     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
mx                      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
fx                      find x forward
Fx                      f backward
tx                      upto x forward
Tx                      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
rx                      replace single character with x
R                       replace characters
nrx                     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


--
※ 来源:.天大求实 BBS bbs.tju.edu.cn.[FROM: bbs.tju.edu.cn]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 17:22 , Processed in 0.022954 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表