分类:
2014-09-03 13:30:49
原文地址:Introducing Vi 作者:东方蜘蛛
Command | Meaning |
vi File Name | Open or Create File |
vi | Open New File To Be Named |
vi -r File Name | Recover Crashed File |
view File Name | Open File Read-Only |
vipw | Edit the /etc/passwd file, setting locks and doing appropriate processing. |
There are three modes of operation: | Command Mode Insert Mode Last Line Mode |
Vi Commands Used To Edit Files Positioning The Cursor |
Command | Meaning |
h | Move left one character |
j | Move down one line |
k | Move up one line |
l | Move right one character |
w | Move right one word |
W | Move right one word (Past Punctuation) |
b | Move left one word |
B | Move left one word (Past Punctuation) |
e | Move to end of current word |
Return | Move down one line |
Backspace | Move left one character |
H | Move to top of screen |
M | Move to middle of screen |
L | Move to bottom on screen |
Control-f | Scroll forward one screen |
Control-d | Scroll forward one-half screen |
Control-b | Scroll backward one-half screen |
G | Go to last line of file |
1G | Go to first line of file |
21G | Go to 21st line of file |
Appending Commands |
Command | Meaning |
a | Append text after cursor |
A | Append text at line end |
i | Insert text before cursor |
I | Insert text at beginning of line |
o | Insert line below cursor |
O | Insert line above cursor |
Deleting Text |
Command | Meaning |
x | Delete Character at the cursor |
X | Delete character to the left of the cursor |
dw | Delete word (or part of word to right of cursor) |
dd | Delete line containing the cursor |
D | Delete part of line to right of cursor |
dG | Delete to end of file |
d1G | Delete from beginning of file to cursor |
:5,10d | Delete lines 5 through 10 |
Changing Text |
Command | Meaning |
CW | Change word (or part of word) to right of cursor |
cc | Change line |
c | Change from cursor to end of line |
s | Substitute string for characters from cursor forward |
r | Replace character at cursor with one other character |
r Return | Break line |
Insert Mode |
Command | Meaning |
J | Join current line and line below |
xp | Transpose character at cursor and character to the right |
~ | Change case of letter (upper or lower ) |
u or :u | Undo previous command |
Undo all changes to cuurent line |
Copying and Pasting |
Command | Meaning |
y | Yank or copy line |
Y | Yank or copy line |
p | Put yanked or deleted line below current |
P | Same as above |
Saving Changes and Quitting |
Command | Meaning |
:w | Save changes (write buffer) |
:w new file | Write buffer to named file |
:wq | Save changes and quit Vi |
:q! | Quit without saving changes |
Displaying and Hiding Line# |
Command | Meaning |
:set nu | Show line numbers |
:set nonu | Hide line numbers; setting is case sensitive |
:set ic | Searches should ignore case |
:set noic | Searches should be case sensitive |
:set list | Display invisible characters |
Search and Replace |
Command | Meaning |
/string | Search for string |
?string | Search backward for string |
n | Find next occurrence of string in search direction |
N | Find previous occurrence of string in search direction |
:%s/old/new/g | Search and replace |
Refresh the Screen and Including Files |
Command | Meaning |
Control-1 | Clear (refresh) scrambled screen |
:r file name | Insert (read) file after cursor |
:34r file name | Insert file after line 34 |