The following tables contain all the basicvi commands.(下表包含了所有基本的vi命令)
Starting vi(启动vi)
Command | Description |
---|---|
vi | start at line 1 offile |
vi | start at line n offile |
vi | start at last line offile |
vi | start at pattern infile |
vi | recover file after a systemcrash |
Saving files and quittingvi(保存和退出vi)
Command | Description |
---|---|
:e file | edit file (save current file with :wfirst) |
:w | save (write out) the file beingedited |
:w file | save asfile |
:w! file | save as an existingfile |
:q | quitvi |
:wq | save the file and quitvi |
:x | save the file if it has changed and quitvi 如果文件被改动,则保存并退出。 |
:q! | quit vi without savingchanges |
Moving the cursor(光标移动)
Keys pressed | Effect |
---|---|
h | left onecharacter |
l or <Space> | right onecharacter |
k | up oneline |
j or <Enter> | down oneline |
b | left oneword |
w | right oneword |
( | start ofsentence |
) | end ofsentence |
{ | start ofparagraph |
} | end ofparagraph |
1G | top offile |
nG | linen |
G | end offile |
<Ctrl>W | first character of insertion |
<Ctrl>U | up ?screen |
<Ctrl>D | down ?screen |
<Ctrl>B | up onescreen |
<Ctrl>F | down onescreen |
Inserting text(文字插入)
Keys pressed | Text inserted |
---|---|
a | after thecursor |
A | after last character on theline |
i | before thecursor |
I | before first character on theline |
o | open line below currentline |
O | open line above currentline |
Changing and replacing text
Keys pressed | Text changed or replaced |
---|---|
cw | word |
3cw | three words |
cc | current line |
5cc | five lines |
r | current character only |
R | current character and those to its right |
s | current character |
S | current line |
~ | switch between lowercase and uppercase |
Deleting text(文本删除)
Keys pressed | Text deleted |
---|---|
x | character undercursor |
12x | 12characters |
X | character to left ofcursor |
dw | word |
3dw | threewords |
d0 | to beginning ofline |
d$ | to end ofline |
dd | currentline |
5dd | fivelines |
d{ | to beginning ofparagraph |
d} | to end ofparagraph |
:1,. d | to beginning offile |
:.,$ d | to end offile |
:1,$ d | wholefile |
Using markers and buffers
Command | Description |
---|---|
mf | set marker named ``f'' |
`f | go to marker ``f'' |
′f | go to start of line containing marker ``f'' |
"s12yy | copy 12 lines into buffer ``s'' |
"ty} | copy text from cursor to end of paragraph into buffer``t'' |
"ly1G | copy text from cursor to top of file into buffer ``l'' |
"kd`f | cut text from cursor up to marker ``f'' into buffer ``k'' |
"kp | paste buffer ``k'' into text |
Searching for text(文本搜索)
Search | Finds |
---|---|
/and | next occurrence of ``and'', for example, ``and'', ``stand'',``grand'' |
and | previous occurrence of ``and'' |
/^The | next line that starts with ``The'', for example, ``The'',``Then'', ``There'' |
/^The\> | next line that starts with the word ``The'' |
/end$ | next line that ends with ``end'' |
/[bB]ox | next occurrence of ``box'' or ``Box'' |
n | repeat the most recent search, in the same direction |
N | repeat the most recent search, in the opposite direction |
Searching for and replacing text(搜索并替换文本)
Command | Description |
---|---|
:s/pear/peach/g | replace all occurrences of ``pear'' with ``peach'' on currentline |
:/orange/s//lemon/g | change all occurrences of ``orange'' into ``lemon'' on next linecontaining ``orange'' |
:.,$/\<file/directory/g | replace all words starting with ``file'' by ``directory'' onevery line from current line onward, for example, ``filename''becomes ``directoryname'' |
:g/one/s//1/g | replace every occurrence of ``one'' with 1, for example,``oneself'' becomes ``1self'', ``someone'' becomes ``some1'' |
Matching patterns of text
expression_r_r_r_r_r_r | Matches |
---|---|
. | any single character |
zero or more of the previous expression_r_r_r_r_r_r | |
. | zero or more arbitrary characters |
\< | beginning of a word |
\> | end of a word |
\ | quote a special character |
\ | the character ``'' |
^ | beginning of a line |
$ | end of a line |
[set] | one character from a set of characters |
[XYZ] | one of the characters ``X'', ``Y'', or ``Z'' |
[[:upper:]][[:lower:]]* | one uppercase character followed by any number of lowercasecharacters |
[^set] | one character not from a set of characters |
[^XYZ[:digit:]] | any character except ``X'', ``Y'', ``Z'', or a numericdigit |
Options to the :set command
Option | Effect |
---|---|
all | list settings of all options |
ignorecase | ignore case in searches |
list | display <Tab> and end-of-linecharacters |
mesg | display messages sent to your terminal |
nowrapscan | prevent searches from wrapping round the end or beginning of afile |
number | display line numbers |
report=5 | warn if five or more lines are changed by command |
term=ansi | set terminal type to ``ansi'' |
terse | shorten error messages |
warn | display ``[No write since last change]'' on shell escape iffile has not been saved |
联系客服