打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux vi 命令全集(Linux vi commands summary)

vi command summary

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

Starting vi(启动vi)

CommandDescription
vi filestart at line 1 offile              光标在第一行
vi +n filestart at line n offile                光标在第n行
vi filestart at last line offile           光标在最后一行
vi +/pattern filestart at pattern infile            光标在pattern行
vi -r filerecover file after a systemcrash      系统down机后恢复文件

 

Saving files and quittingvi(保存和退出vi) 

CommandDescription
:e fileedit file (save current file with :wfirst)       编辑file
:wsave (write out) the file beingedited             保存当前文件
:w filesave asfile                               保存为file
:w! filesave as an existingfile                      强制保存
:qquitvi                              退出
:wqsave the file and quitvi                     保存并退出
:xsave the file if it has changed and quitvi 如果文件被改动,则保存并退出。
:q!quit vi without savingchanges                放弃修改并退出

 

Moving the cursor(光标移动)

Keys pressedEffect
hleft onecharacter                       左移一个字符
l or <Space>right onecharacter                        右移一个字符
kup oneline                               上移一行
j or <Enter>down oneline                              下移一行
bleft oneword                              左移一个字
wright oneword                             右移一个字
(start ofsentence                          到达一句的开头
)end ofsentence                           到达一句的结尾
{start ofparagraph                         到达一段的开头
}end ofparagraph                          到达一段的结尾
1Gtop offile                                到达文件的开头
nGlinen                                到达第n行
Gend offile                                到达文件末尾
<Ctrl>Wfirst character of insertion
<Ctrl>Uup ?screen                                上滚半屏
<Ctrl>Ddown ?screen                               下滚半屏
<Ctrl>Bup onescreen                              上滚一屏
<Ctrl>Fdown onescreen                            下滚一屏

 

Inserting text(文字插入)

Keys pressedText inserted
aafter thecursor                           光标后插入
Aafter last character on theline           行尾插入
ibefore thecursor                         光标前插入
Ibefore first character on theline         行首插入
oopen line below currentline               行下插入一行
Oopen line above currentline               行上插入一行

 

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 undercursor                      删除光标右侧文字
12x12characters                               删除12个字符
Xcharacter to left ofcursor                 删除光标左侧字符
dwword                                        删除一个单词
3dwthreewords                                 删除三个单词
d0to beginning ofline                        删除至行首
d$to end ofline                              删除至行尾
ddcurrentline                                 删除当前行
5ddfivelines                                  删除五行
d{to beginning ofparagraph                   删除至段首
d}to end ofparagraph                         删除至段尾
:1,. dto beginning offile                        删除至文件首
:.,$ dto end offile                             删除至文件尾
:1,$ dwholefile                                  删除整个文件

 

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
and

previous occurrence of ``and''  

                                                     向上搜索文字and

/^The

next 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]ox

next occurrence of ``box'' or ``Box'' 

                                                     搜索box或者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(搜索并替换文本)

CommandDescription
:s/pear/peach/g

replace all occurrences of ``pear'' with ``peach'' on currentline 

                            在当前行搜索pear,并替换为peach

:/orange/s//lemon/g

change all occurrences of ``orange'' into ``lemon'' on next linecontaining ``orange'' 

                            在下一行中搜索orange,并替换为lemon

:.,$/\<file/directory/greplace 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''

                          用“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 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

OptionEffect
alllist settings of all options
ignorecaseignore case in searches
listdisplay <Tab> and end-of-linecharacters
mesgdisplay messages sent to your terminal
nowrapscanprevent searches from wrapping round the end or beginning of afile
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 iffile has not been saved

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Vi Cheat Sheet
如何灵活的运用VI编辑器
Mac下vi/vim开启语法高亮&着色丨Enable vi/vim syntax highlighting on Mac
sed
Unix/Linux中编辑文件的命令VI详细介绍
[Linux探索之旅]第三部分第五课:延时执行,唯慢不破
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服