您的位置:首页 > 其它

【Unix】vi command summary

2014-12-12 10:35 211 查看


vi command summary

The following tables contain all the basic vi commands.(下表包含了所有基本的vi命令)

Starting vi(启动vi)
CommandDescription
vi filestart at line 1 of file              光标在第一行
vi +n filestart at line n of file                光标在第n行
vi + filestart at last line of file            光标在最后一行
vi +/pattern filestart at pattern in file             光标在pattern行
vi -r filerecover file after a system crash       系统down机后恢复文件
 

Saving files and quitting vi(保存和退出vi) 
CommandDescription
:e fileedit file (save current file with :w first)        编辑file
:wsave (write out) the file being edited              保存当前文件
:w filesave as file                                保存为file
:w! filesave as an existing file                       强制保存
:qquit vi                               退出
:wqsave the file and quit vi                      保存并退出
:xsave the file if it has changed and quit vi 如果文件被改动,则保存并退出。
:q!quit vi without saving changes                 放弃修改并退出
 

Moving the cursor(光标移动)
Keys pressedEffect
hleft one character                        左移一个字符
l or <Space>right one character                        右移一个字符
kup one line                                上移一行
j or <Enter>down one line                               下移一行
bleft one word                               左移一个字
wright one word                              右移一个字
(start of sentence                           到达一句的开头
)end of sentence                            到达一句的结尾
{start of paragraph                          到达一段的开头
}end of paragraph                           到达一段的结尾
1Gtop of file                                 到达文件的开头
nGline n                                 到达第n行
Gend of file                                 到达文件末尾
<Ctrl>Wfirst character of insertion
<Ctrl>Uup ½ screen                                 上滚半屏
<Ctrl>Ddown ½ screen                                下滚半屏
<Ctrl>Bup one screen                               上滚一屏
<Ctrl>Fdown one screen                             下滚一屏
 

Inserting text(文字插入)
Keys pressedText inserted
aafter the cursor                            光标后插入
Aafter last character on the line            行尾插入
ibefore the cursor                          光标前插入
Ibefore first character on the line          行首插入
oopen line below current line                行下插入一行
Oopen line above current line                行上插入一行
 

Changing and replacing text
Keys pressedText changed or replaced
cwword
3cwthree words
cccurrent line
5ccfive lines
rcurrent character only
Rcurrent character and those to its right
scurrent character
Scurrent line
~switch between lowercase and uppercase
 

Deleting text(文本删除)
Keys pressedText deleted
xcharacter under cursor                       删除光标右侧文字
12x12 characters                                删除12个字符
Xcharacter to left of cursor                  删除光标左侧字符
dwword                                         删除一个单词
3dwthree words                                  删除三个单词
d0to beginning of line                         删除至行首
d$to end of line                               删除至行尾
ddcurrent line                                 删除当前行
5ddfive lines                                   删除五行
d{to beginning of paragraph                    删除至段首
d}to end of paragraph                          删除至段尾
:1,. dto beginning of file                         删除至文件首
:.,$ dto end of file                              删除至文件尾
:1,$ dwhole file                                   删除整个文件
 

Using markers and buffers
CommandDescription
mfset marker named ``f''
`fgo to marker ``f''
´fgo to start of line containing marker ``f''
"s12yycopy 12 lines into buffer ``s''
"ty}copy text from cursor to end of paragraph into buffer ``t''
"ly1Gcopy text from cursor to top of file into buffer ``l''
"kd`fcut text from cursor up to marker ``f'' into buffer ``k''
"kppaste buffer ``k'' into text
 

Searching for text(文本搜索)
SearchFinds
/andnext occurrence of ``and'', for example, ``and'', ``stand'', ``grand'' 

                                                      向下搜索文字and
?andprevious occurrence of ``and''  

                                                      向上搜索文字and
/^Thenext line that starts with ``The'', for example, ``The'', ``Then'', ``There''

                                                      搜索下一个以the开头的行
/^The\>next line that starts with the word ``The'' 

                                                      搜索下一个以整字The开头的行
/end$next line that ends with ``end'' 

                                                      搜索下一个以end结尾的行
/[bB]oxnext occurrence of ``box'' or ``Box'' 

                                                      搜索box或者Box
nrepeat the most recent search, in the same direction 

                                                      在相同方向上继续搜索
Nrepeat the most recent search, in the opposite direction 

                                                      在相反方向上继续搜索
 

Searching for and replacing text(搜索并替换文本)
CommandDescription
:s/pear/peach/greplace all occurrences of ``pear'' with ``peach'' on current line 

                            在当前行搜索pear,并替换为peach
:/orange/s//lemon/gchange all occurrences of ``orange'' into ``lemon'' on next line containing ``orange'' 

                            在下一行中搜索orange,并替换为lemon
:.,$/\<file/directory/greplace all words starting with ``file'' by ``directory'' on every line from current line onward, for example, ``filename'' becomes ``directoryname'' 
:g/one/s//1/greplace every occurrence of ``one'' with 1, for example, ``oneself'' becomes ``1self'', ``someone'' becomes ``some1''

                           用“1”替换所有的"one"
 

Matching patterns of text
expression_r_r_r_r_r_rMatches
.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 lowercase characters
[^set]one character not from a set of characters
[^XYZ[:digit:]]any character except ``X'', ``Y'', ``Z'', or a numeric digit
 

Options to the :set command
OptionEffect
alllist settings of all options
ignorecaseignore case in searches
listdisplay <Tab> and end-of-line characters
mesgdisplay messages sent to your terminal
nowrapscanprevent searches from wrapping round the end or beginning of a file
numberdisplay line numbers
report=5warn if five or more lines are changed by command
term=ansiset terminal type to ``ansi''
terseshorten error messages
warndisplay ``[No write since last change]'' on shell escape if file has not been saved
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: