Vi Control Keys
File Manipulation
Line Positioning
Undo previous change
u,u
Top/Last/Middle line on screen
H,L,M
Exit vi, saving changes if modified
ZZ
Next (Previous) line, at first non-white space character
+ or , -
(Forced)Write back changes
:w(!)
Next (Previous) line, same column
j,k | down/up
Write/Overwrite file name
:w(!) name
Character Positioning
Quit, discarding changes (Forced)
:q(!)
Beginning (End) of line
0, $
Edit file name | Reedit, discard changes
:e name | :e!
First non-white space character
^
Edit, starting at end | Edit, starting at line n
:e + name | :e +n
Forward (Backward)
l,h or ->,
Edit alternate file (, discard changes)
:e(!) #
Backspace, Space bar
^H, space
Run shell | command, then return
:sh | :!cmd
Find next (previous) x
f(F)x
Edit next file in arglist | specify new arglist
:n | :n args
Move to character following the next(previous) x
t(T)x
Show current file and line
^G
Repeat last(inverse) of last f,F,t, or T
;,'
Position cursor to tag
:ta tag
Move to column n
,n|
Positioning Within a File
Find matching () or {}
%
Forward/Backward screen
^F, ^B
Words, Sentences, Paragraphs
Scroll down/up half screen
^D, ^U
Forward (Back) a word
w,b
Go to the beginning of the specified line
#G
Forward (Back) a blank-delimited word
W, B
Next (Previous) line matching pattern
/(?)pattern
End of a (blank-delimited) word
e,W
Repeat(Reverse) last / or ? Command
n,N
To next (previous) sentence
),(
,nth line after (before) pattern
/pat/+n,?pat?-n
To next (previous) paragraph
},{
Next (Previous) section/function
]], [[
Corrections During Insert
Beginning (End) of sentence | Paragraph
(, ) | {,}
Erase last character (word)
^H, ^W
Find matching () or {}
%
Interrupt, suspends insert mode
CTRL-C
Adjusting the Screen
Ends insertion, back to command mode
ESC
Clear and redraw window (if ^L is ->key)
^L(, ^R)
Backtab on character, reset left margin of autoindent
CTRL-D
Redraw screen with current line at top/bottom/center of window
z/z-/z.
Insert and Replace
Move pattern line to bottom of window
/pat/z-
Append after cursor/at end of line
a/A
Use n-line window
zn.
Insert before cursor/first non-blank
i/I
Scroll window down(up) one line
^E,^Y
Open line below/above
o/O
Marking and Returning
Replace single character with x
,rx
Mark current position with the ASCII lower-case letter x
,mx
Replace characters
Rtext
Move to mark x
`x
Copy & Paste
Operators
Copy 3 lines/characters
3yy/3yl
Delete/change/yank lines to buffer
d/c/y
Copy to/paste from buffer x
“xy/”xp
Left shift/Right shift/Filter through command
/!
Paste back text after/before cursor
p/P
Miscellaneous Operations
Delete into buffer x
“xd
Change/Delete rest of line
c$/d$
Undo, Redo, Retrieve
Substitute characters/lines
cl/cc
Undo last change
u
Delete characters (before cursor)
dl(dh)
Restore current line
U
Join/Yank lines
J/yy
Repeat last change
.
/usr/bin/vi [-r filename] [-R] [-wn]
-r: recovery file; -R: readonly; -wn: set the default window size to n
' sed -e “/^$/d” filename -- remove all blank lines from a file
:set – show all vi varibles; :set nu/nonu – show line number; :set smd – show status
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/40653/showart_366498.html
页:
[1]