linux--VIM命令大全.docx_第1页
linux--VIM命令大全.docx_第2页
linux--VIM命令大全.docx_第3页
linux--VIM命令大全.docx_第4页
linux--VIM命令大全.docx_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

基础:e filenameOpenfilenamefor edition:wSave file:qExit Vim:q!Quit without saving:xWrite file (if changes has been made) and exit:sav filenameSaves file asfilename.Repeats the last change made in normal mode5.Repeats 5 times the last change made in normal mode在文件中移动k or Up Arrowmove the cursor up one linej or Down Arrowmove the cursor down one lineemove the cursor to the end of the wordbmove the cursor to the begining of the word0move the cursor to the begining of the lineGmove the cursor to the end of the lineggmove the cursor to the begining of the fileLmove the cursor to the end of the file:59move cursor to line59. Replace59by the desired line number.20|move cursor to column20.%Move cursor to matching parenthesisJump to function startJump to block start剪切、复制和粘贴yCopy the selected text to clipboardpPaste clipboard contentsddCut current lineyyCopy current liney$Copy to end of lineDCut to end of line搜索/wordSearchwordfrom top to bottom?wordSearchwordfrom bottom to top*Search the word under cursor/cstringSearchSTRINGorstring, case insensitive/johanSearchjohnorjoan/Searchtheorbreathe/Searchthe/Search all words of 4 letters/Searchfredbut notalfredorfrederick/fred|joeSearchfredorjoe/Search exactly 4 digits/n3Find 3 empty lines:bufdo /searchstr/Search in all open filesbufdo %s/something/somethingelse/gSearchsomethingin all the open buffers and replace it withsomethingelse替换:%s/old/new/gReplace all occurences ofoldbynewin file:%s/onward/forward/giReplace onward by forward, case unsensitive:%s/old/new/gcReplace all occurences with confirmation:2,35s/old/new/gReplace all occurences between lines 2 and 35:5,$s/old/new/gReplace all occurences from line 5 to EOF:%s/hello/gReplace the begining of each line byhello:%s/$/Harry/gReplace the end of each line byHarry:%s/onward/forward/giReplaceonwardbyforward, case unsensitive:%s/ *$/gDelete all white spaces:g/string/dDelete all lines containingstring:v/string/dDelete all lines containing which didnt containstring:s/Bill/Steve/Replace the first occurence ofBillbyStevein current line:s/Bill/Steve/gReplaceBillbyStevein current line:%s/Bill/Steve/gReplaceBillbyStevein all the file:%s/M/gDelete DOS carriage returns (M):%s/r/r/gTransform DOS carriage returns in returns:%s#+#gDelete HTML tags but keeps text:%s/(.*)n1$/1/Delete lines which appears twiceCtrl+aIncrement number under the cursorCtrl+xDecrement number under cursorggVGg?Change text to Rot13大小写VuLowercase lineVUUppercase linegInvert casevEUSwitch word to uppercasevEModify word caseggguGSet all text to lowercasegggUGSet all text to uppercase:set ignorecaseIgnore case in searches:set smartcaseIgnore case in searches excepted if an uppercase letter is used:%s/./u&/gSets first letter of each word to uppercase:%s/ outfileAppends lines 1 to 10 tooutfile:r infileInsert the content ofinfile:23r infileInsert the content ofinfileunder line 23文件浏览器:e .Open integrated file explorer:SexSplit window and open integrated file explorer:Sex!Same as:Sexbut split window vertically:browse eGraphical file explorer:lsList buffers:cd .Move to parent directory:argsList files:args *.phpOpen file list:grep expression *.phpReturns a list of .php files conteningexpressiongfOpen file name under cursor和 Unix 系统交互:!pwdExecute thepwdunix command, then returns to Vi!pwdExecute thepwdunix command and insert output in file:shTemporary returns to Unix$exitRetourns to Vi对齐:%!fmtAlign all lines!fmtAlign all lines at the current position5!fmtAlign the next 5 linesTabs/Windows:tabnewCreates a new tabgtShow next tab:tabfirstShow first tab:tablastShow last tab:tabm n(position)Rearrange tabs:tabdo %s/foo/bar/gExecute a command in all tabs:tab ballPuts all open files in tabs:new abc.txtEditabc.txtin new window分屏显示:e filenameEditfilenamein current window:split filenameSplit the window and openfilenamectrl-w up arrowPuts cursor in top windowctrl-w ctrl-wPuts cursor in next windowctrl-w_Maximize current window verticallyctrl-w|Maximize current window horizontallyctrl-w=Gives the same size to all windows10 ctrl-w+Add 10 lines to current window:vsplit fileSplit window vertically:sview fileSame as:splitin readonly mode:hideClose current window:nlyClose all windows, excepted current:b 2Open #2 in this window自动完成Ctrl+n Ctrl+p (in insert mode)Complete wordCtrl+x Ctrl+lComplete line:set dictionary=dictDefinedictas a dictionnaryCtrl+x Ctrl+kComplete with dictionnaryMarksm a-zMarks current position asa-z a-zMove to positiona-zMove to previous position缩写:ab mail Definemailas abbreviation 文本缩进:set autoindentTurn on auto-indent:set smartindentTurn on intelligent auto-indent:set shiftwidth=4Defines 4 spaces as indent sizectrl-t, ctrl-dIndent/un-indent in insert modeIndentUn-indent=%Indent the code between parenthesis1GVG=Indent the whole file语法高亮:syntax onTurn on syntax highlighting:syntax offTurn off syntax highlighting:set syntax=perlForce syntax highlighting插入模式下的命令:一般使用Vim时都在正常模式下,但如果知道几个专门用于插入模式下的快捷命令,会感觉更快捷一些。参考:help insert-index,事实上插入模式下的自动补全功能,那个才真正给力。调整缩进 在插入模式下如果希望调整行的缩进,可以返回正常模式,或者调整缩进,然后使用i或者a返回插入模式下,要按3次键,下面的组合键能够实现在插入模式下的缩进调整,每次调整一个shiftwidth宽度。这个尤其用在写if之类的缩进结构时候,很方便。CTRL+D 减少缩进CTRL+T 增加缩进复制相邻行的内容 写东西的时候经常出现相邻两行的内容很想近的情况,你可以用复制粘贴功能,也可以直接一个字符一个字符地复制。CTRL+Y 复制上一行的相同列的字符CTRL+E 复制下一行的相同列的字符举个实际的例子,比如一行内容是:num1 is 数字 在这一行下方新增加一个空白行(插入模式下在行尾回车或者正常模式下按o),光标在num1的n正下方,这时候按3下,num被复制到当前位置,输入数字2后继续,空格和汉字也能够正确被一个一个地复制下来。粘贴剪贴板 在插入模式下 0-9a-z%#*:=能够插入剪贴板的内容,如果想临时查看各个剪贴板的内容,可以使用:reg,会显示出各个剪贴板的内容。当然输入这个命令很麻烦,做个快捷键吧,把下面这句放到你的vimrc里面,当然F3可以换成其他功能键,这样你在插入模式下就可以按F3列出所有剪贴板的当前内容,然后剪贴板名称吧,这样做的好处是粘贴完仍然在插入模式下。imap :reg快速移动光标 插入模式下快速移动光标的命令不太多,除了、到行首、行尾之外,也可以以单词为单位移动,总比一个字符一个字符移动快一点。或 光标左移一个单词或 光标右移一个单词快速删除 默认情况下Vim在插入模式下只提供了向左删除的快捷键,用不用你自己看着办吧。CTRL+W 删除光标左侧的单词CTRL+U 删除光标左侧的行常用命令1.vim#在命令行中输入vim,进入vim编辑器2.i#按一下i键,下端显示 -INSERT-#插入命令,在vim中可能任意字符都有作用3.Esc#退出i(插入)命令进行其它命令使用4.:r filename#读入一个文件内容,并写入到当前编辑器中5.:w newfilename#将该编辑器中的内容写入到一个新文件中6.:w#在编辑的过程中保存文件,相当于word中的ctrl+s7.:! command暂时离开 vi 到指令列模式下执行 command 的显示结果!例如:!ls#在编辑过程中执行shell命令ls8.:sh#进入shell命令行,执行完命令后ctrl+d退出重新进入vim编辑继续编辑在shell命令下,执行ctral+l完成清屏9.:wq#保存文件并退出10.ZZ#保存文件并退出,同上一个命令,注意大写11.:q!#强制退出,不保存12.:set number或者:set nu#使编辑中的文件显示行号13.:set nonumber或者:set nonu#与上一条命令相反,不显示行号14.:help i#查看插入命令帮助15.u#撤消上一步操作16./Fedora#查找Fedora字符17.:s /Fedora/Redhat#将Fedora字符替换为Redhat(只替换在光标所在的行)18.dw#删除单词dd#删除行19.o#打开空白一行20.vim + filename#进行文件最后一行进行编辑21.vim +n filename#进入文件第n行进行编辑22.:1,.s/redhat/fedora#.号表示当前行,即光标所在行#将第1行到当前行(.)第一次出现的redhat字符代替为fedora23.:1,.s/redhat/fedora/g#将第1行到当前行(.)所有出现的redhat字符代替为fedora,g全局标志24.:1,$s/redhat/fedora/g#$表示最后一行#将第1行到最后一行所有出现的redhat字符代替为fedora25.:%s/redhat/fedora/g#同上一个命令26.:%s/fedora/g#将第1行到最后一行所有出现的redhat字代替为fedora#字,而不是字符27.:f#显示文件内容,状态等等#同ctrl+g命令28.:e!#当前文件,返回到上次保存:e file#切换编辑文件29.:n#当编辑时有多个文件(比如vim file1 file2)时切换到下一个文件,与:e file结合使用 VIM命令大全光标控制命令命令 光标移动h 向左移一个字符j 向下移一行k 向上移一行l 向右移一个字符G 移到文件的最后一行w 移到下一个字的开头W 移到下一个字的开头,忽略标点符号b 移到前一个字的开头B 移到前一个字的开头,忽略标点符号L 移到屏幕的最后一行M 移到屏幕的中间一行H 移到屏幕的第一行e 移到下一个字的结尾E 移到下一个字的结尾,忽略标点符号( 移到句子的开头) 移到句子的结尾 移到段落的开头 移到下一个段落的开头0(数字), | 移到当前行的第一列 移到当前行的第一个非空字符$ 移到当前行的最后一个字符+, Enter 移到下一行的第一个字符- 移到前一行的第一个非空字符在 vi 中添加文本命令 插入动作a 在光标后插入文本A 在当前行插入文本i 在光标前插入文本I 在当前行前插入文本o 在当前行的下边插入新行O 在当前行的上边插入新行s 删除光标所在处字符,并进入插入模式S 删除光标所在的行,并进入插入模式:r file 读入文件 file 内容,并插在当前行后:nr file 读入文件 file 内容,并插在第 n 行后Esc 回到命令模式v char 插入时忽略 char 的指定意义,这是为了插入特殊字符在 vi 中删除文本命令 删除操作x 删除光标处的字符dw 删至下一个字的开头dG 删除行,直到文件结束dd 删除整行db 删除光标前面的字:n,md 从第 m 行开始往前删除 n 行d, d$ 从光标处删除到行尾h, backspace 插入时,删除前面的字符w 插入时,删除前面的字修改 vi 文本每个命令前面的数字表示该命令重复的次数命令 替换操作rchar 用 char 替换当前字符R text escape 用 text 替换当前字符直到按下 Esc 键stext escape 用 text 代替当前字符S 或 cctext escape 用 text 代替整行cwtext escape 将当前字改为 textCtext escape 将当前行余下的改为 textcG escape 修改至文件的末尾ccursor_cmd text escape 从当前位置处到光标命令位置处都改为 text在 vi 中查找与替换命令 查找与替换操作/text 在文件中向前查找 text?text 在文件中向后查找 textn 在同一方向重复查找N 在相反方向重复查找ftext 在当前行向前查找 textFtext 在当前行向后查找 textttext 在当前行向前查找 text,并将光标定位在 text 的第一个字符Ttext 在当前行向后查找 text,并将光标定位在 text 的第一个字符:set ic 查找时忽略大小写:set noic 查找时对大小写敏感:ranges/pat1/pat2/g 用 newtext 替换 oldtext:m,ns/oldtext/newtext 在 m 行通过 n,用 newtext 替换 oldtext& 重复最后的 :s 命令:g/text1/s/text2/text3 查找包含 text1 的行,用 text3 替换 text2:g/text/command 在所有包含 text 的行运行 command 所表示的命令:v/text/command 在所有不包含 text 的行运行 command 所表示的命令在 vi 中复制文本命令 复制操作yy 将当前行的内容放入临时缓冲区nyy 将 n 行的内容放入临时缓冲区p 将临时缓冲区中的文本放入光标后P 将临时缓冲区中的文本放入光标前(a-z)nyy 复制 n 行放入名字为圆括号内的可命名缓冲区,省略 n 表示当前行(a-z)ndd 删除 n 行放入名字为圆括号内的可命名缓冲区,省略 n 表示当前行(a-z)p 将名字为圆括号的可命名缓冲区的内容放入当前行后(a-z)P 将名字为圆括号的可命名缓冲区的内容放入当前行前在 vi 中撤消与重复命令 撤消操作u 撤消最后一次修改U 撤消当前行的所有修改. 重复最后一次修改, 以相反的方向重复前面的 f、F、t 或 T 查找命令; 重复前面的 f、F、t 或 T 查找命令np 取回最后第 n 次的删除(缓冲区中存有一定次数的删除内容,一般为 9)n 重复前面的 / 或 ? 查找命令N 以相反方向重复前面的 / 或 ? 命令保存文本和退出 vi命令 保存和/或退出操作:w 保存文件但不退出 vi:w file 将修改保存在 file 中但不退出 vi:wq 或 ZZ 或 :x 保存文件并退出 vi:q! 不保存文件,退出 vi:e! 放弃所有修改,从上次保存文件开始再编辑vi 中的选项选项 作用:set all 打印所有选项:set nooption 关闭 option 选项:set nu 每行前打印行号:set showmode 显示是输入模式还是替换模式:set autoindent 继承前一行的缩进方式,特别适用于多行注释:set smartindent 为C程序提供自动缩进:set list 显示制表符(I)和行尾符号:set ts=8 为文本输入设置 tab stops:set window=n 设置文本窗口显示 n 行:set number 显示行数:set nonumber 取消显示行数vi 的状态选项 作用:.= 打印当前行的行号:= 打印文件中的行数ctrl+g 显示文件名、当前的行号、文件的总行数和文件位置的百分比:l 使用字母 l 来显示许多的特殊字符,如制表符和换行符在文本中定位段落和放置标记选项 作用 在第一列插入 来定义一个段落 回到段落的开头处 向前移到下一个段落的开头处m(a-z) 用一个字母来标记当前位置,如用 mz 表示标记 z(a-z) 将光标移动到指定的标记,如用 z 表示移动到 z在 vi 中连接行选项 作用J 将下一行连接到当前行的末尾nJ 连接后面 n 行光标放置与屏幕调整选项 作用H 将光标移动到屏幕

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论