VIM 常用命令集锦

来源:互联网 发布:lm324n中文数据手册 编辑:程序博客网 时间:2024/05/19 00:17

VIM 常用命令集锦

 gf 打开的当前光标下的文件        

 Ctrl +e  Ctrol+y  按照上/下行写


vim中其它的补全方式包括:

整行补全                        CTRL-X CTRL-L根据当前文件里关键字补全        CTRL-X CTRL-N根据字典补全                    CTRL-X CTRL-K根据同义词字典补全              CTRL-X CTRL-T根据头文件内关键字补全          CTRL-X CTRL-I根据标签补全                    CTRL-X CTRL-]补全文件名                      CTRL-X CTRL-F补全宏定义                      CTRL-X CTRL-D补全vim命令                     CTRL-X CTRL-V用户自定义补全方式              CTRL-X CTRL-U拼写建议                        CTRL-X CTRL-S

%  在代码块之间跳转, 一般是()或[]或{}

C-w p  上次编辑的窗口

C-w w  多窗口间交换

C-b C-f 下一页

g/pattern/d 是找到pattern, 删之
v/pattern/d 是找到非pattern,删

C-W +   增加split当前窗口大小

C-W - 减小split当前窗口大小

df<char>  向前删除包含char

dt<char> 向前删除不包含char


100 Vim commands every programmer should know=============================================Published on June 30th, 2008 by Jean-Baptiste Jung. 118 Comments -Since the 70â²s, Vi is one of the programmerâs best friend. Nevermind youâre new to Vi or not, hereâs a big list of 100 useful commands, organized by topic, which will make your coder life better.Basics======:e filenameOpen filename for edition:wSave file:qExit Vim:w!Exit Vim without savingSearch======/wordSearch word from top to bottom?wordSearch word from bottom to top/jo[ha]nSearch john or joan/\<theSearch the, theatre or then/the\>Search the or breathe/\<the\>Search the/\<.\{4}\>Search all words of 4 letters/\/Search fred but not alfred or frederick/fred\|joeSearch fred or joe/\<\d\d\d\d\>Search exactly 4 digits/^\n\{3}Find 3 empty lines:bufdo /searchstr/Search in all open filesReplace=======:%s/old/new/gReplace all occurences of old by new in file:%s/old/new/gwReplace 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 by hello:%s/$/Harry/gReplace the end of each line by Harry:%s/onward/forward/giReplace onward by forward, case unsensitive:%s/ *$//gDelete all white spaces:g/string/dDelete all lines containing string:v/string/dDelete all lines containing which didnât contain string:s/Bill/Steve/Replace the first occurence of Bill by Steve in current line:s/Bill/Steve/gReplace Bill by Steve in current line:%s/Bill/Steve/gReplace Bill by Steve in all the file:%s/\r//gDelete DOS carriage returns (^M):%s/\r/\r/gTransform DOS carriage returns in returns:%s#<[^>]\+>##gDelete HTML tags but keeps text:%s/^\(.*\)\n\1$/\1/Delete lines which appears twiceCtrl+aIncrement number under the cursorCtrl+xDecrement number under cursorggVGg?Change text to Rot13 CaseVuLowercase lineVUUppercase lineg~~Invert casevEUSwitch word to uppercasevE~Modify word caseggguGSet all text to lowercase: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/\<./\l&/gSets first letter of each word to lowercase:%s/.*/\u&Sets first letter of each line to uppercase:%s/.*/\l&Sets first letter of each line to lowercaseRead/Write files================:1,10 w outfileSaves lines 1 to 10 in outfile:1,10 w >> outfileAppends lines 1 to 10 to outfile:r infileInsert the content of infile:23r infileInsert the content of infile under line 23File explorer============:e .Open integrated file explorer:SexSplit window and open integrated file explorer: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 contening expressiongfOpen file name under cursorInteract with Unix:!pwdExecute the pwd unix command, then returns to Vi!!pwdExecute the pwd unix command and insert output in file:shTemporary returns to Unix$exitRetourns to ViAlignment========:%!fmtAlign all lines!}fmtAlign all lines at the current position5!!fmtAlign the next 5 linesTabs====: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 tabsWindow spliting==============:e filenameEdit filename in current window:split filenameSplit the window and open filenamectrl-w up arrowPuts cursor in top windowctrl-w ctrl-wPuts cursor in next windowctrl-w_Maximise current windowctrl-w=Gives the same size to all windows10 ctrl-w+Add 10 lines to current window:vsplit fileSplit window vertically:sview fileSame as :split in readonly mode:hideClose current window:nlyClose all windows, excepted current:b 2Open #2 in this windowAuto-completion===============Ctrl+n Ctrl+p (in insert mode)Complete wordCtrl+x Ctrl+lComplete line:set dictionary=dictDefine dict as a dictionnaryCtrl+x Ctrl+kComplete with dictionnaryMarks=====mkMarks current position as k~KMoves cursor to mark kdâ¢kDelete all until mark kAbbreviations=============:ab mail mail@provider.orgDefine mail as abbreviation of mail@provider.orgText indent==========: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 mode>>Indent<<Un-indentSyntax highlighting==================:syntax onTurn on syntax highlighting:syntax offTurn off syntax highlighting:set syntax=perlForce syntax highlighting


打开编辑:    【e filename】编辑指定文件。切换到插入模式:i   插入到当前光标下的字母的前面a   插入到当前光标下的字母的后边o   在当前行的下一行插入一个新行O   在当前行的上一行插入一个新行移动光标:    「h」、「j」、「k」、「l」,分别控制光标左、下、上、右移一格   按「ctrl」+「b」:屏幕往“后”移动一页。  按「ctrl」+「f」:屏幕往“前”移动一页。  按「ctrl」+「u」:屏幕往“后”移动半页。  按「ctrl」+「d」:屏幕往“前”移动半页。  按数字「0」:移到光标所在行的“行首”,就是第0列。  按「^」:移动到光标所在行的“行首”,不计算前面的空格。  按「$」:移动到光标所在行的“行尾”。  按「G」:移动到文章的最后。  按「gg」:移动到文章的开头。  按「w」:光标跳到下个字的开头。  按「e」:光标跳到下个字的字尾。  按「b」:光标回到上个字的开头。  按「#l」:光标移到该行的第#个位置,如:5l,56l。    按 [f]: 行内向前查找某个字符。    按 [F]: 行内向后查找某个字符。删除文字:  「x」:每按一次,删除光标所在位置的“后面”一个字符。  「#x」:例如,「6x」表示删除光标所在位置的“后面”6个字符。  「X」:大写的X,每按一次,删除光标所在位置的“前面”一个字符。  「#X」:例如,「20X」表示删除光标所在位置的“前面”20个字符。  「dd」:删除光标所在行。  「#dd」:从光标所在行开始删除#行。复制:  「yw」:将光标所在之处到字尾的字符复制到缓冲区中。  「#yw」:复制#个字到缓冲区  「yy」:复制光标所在行到缓冲区。  「#yy」:例如,「6yy」表示拷贝从光标所在的该行“往下数”6行文字。  「p」:将缓冲区内的字符贴到光标所在位置。注意:所有与“y”有关的复制命令都必须与“p”配合才能完成复制与粘贴功能。替换:  「r」:替换光标所在处的字符。  「R」:替换光标所到之处的字符,直到按下「ESC」键为止。撤销和重做:  「u」:如果您误执行一个命令,可以马上按下「u」,回到上一个操作。按多次“u”可以执行多次回复。    [C-r]: redo.重做命令。更改:  「cw」:更改光标所在处的字到字尾处。  「c#w」:例如,「c3w」表示更改3个字。跳至指定的行:  「ctrl」+「g」列出光标所在行的行号。  「#G」:例如,「15G」,表示移动光标至文章的第15行行首。A) 列出行号 「set nu」:输入「set nu」后,会在文件中的每一行前面列出行号。B) 跳到文件中的某一行 「#」:「#」号表示一个数字,在冒号后输入一个数字,再按回车键就会跳到该行了,如输入数字15,再回车,就会跳到文章的第15行。C) 查找字符 「/关键字」:先按「/」键,再输入您想寻找的字符,如果第一次找的关键字不是您想要的,可以一直按「n」会往后寻找到您要的关键字为止。从开头找。 「?关键字」:先按「?」键,再输入您想寻找的字符,如果第一次找的关键字不是您想要的,可以一直按「n」会往前寻找到您要的关键字为止。从末尾找。D) 保存文件 「w」:在冒号输入字母「w」就可以将文件保存起来。E) 离开vi 「q」:按「q」就是退出,如果无法离开vi,可以在「q」后跟一个「!」强制离开vi。 「qw」:一般建议离开时,搭配「w」一起使用,这样在退出的时候还可以保存文件。区块选择:    v :字符选择,会将光标经过癿地方反白选择!    V(大写) :行选择,会将光标经过癿行反白选择!    [Ctrl]+v : 区块选择,可以用长方形癿方式选择资料    y :将反白癿地方复制起来 d 将反白癿地方删除掉区块替换:    C-V: 然后使用hjkl选中块操作区域。使用I在区域前插入,一般用于单行注释,使用A添加到后边,使用r全部替换成一个字符,            使用c的话,使用输入词替换每一行。然后使用ESC使操作对整个区块生效。



Basic Editing=============Basics------hjkl    Eursor keysi       Enter insert mode, cursor turns from a blok into a vertial line,            new entered before current char.x       Delete current character.X       Delete the one to the left.A       Insert text at the end of line.Extras------u       Undo the last action. vim unlimited undo.C-R     Redo action.0       Jumps directly to the beginning of the line.$       Jumps directly to the end of the line.^       Jumps directly to the first non-blank.w,e,b   Move along 'words'.W,E,B   Move along 'WORDs'.R       Enter inset mode with a overstrike cursor. witch types over existing characters.:w<CR>  Save.:q<CR>  Quit.Operators & Repetition======================Basics------f       Moves the cursor to the next instance of that character on the current line.F       Does the same backwards.t       Same as 'f', but stop right before the character.T       Same as 'F', but stop right before the character.d       Delete, followed, by any motion deletes the next between the cursor             and that motion's destination. 'dw','df-'.c       Change, does the same like R, but leaves you in insert mode..       Repeats the last editing action. Extras------Prepend a count to any command/motion to repeat it that number of times.d2w     Delete up to the second word.d2t,    Delete up to but not including the second comma.2i      Repeats the text after you press(ESC) to finish the input session.cc      Change,operator on the current line.dd      Delete, operator on the current line.v       Enters visual mode.V       Enters visual line mode.C-v     Selects rectangular blocks.Yank & Paste============Basics------y       Followed by any motion to yank(copy). p       Paste after(if charwise, to the right, if linewise, below)P       Paste before.yy      Copy the current line.y       Works also but in visual mode.Note: Text deleted with d,c,x...is also copied.Extras------"a-z    Before any yank/delete/paste command choose a register."A-Z    Same as above but append only."* or "+    Select the system clipboard.o       Enters insert mode in a new line below the current one.O       Does the same above the current line.Searching=========Basics------/       Basic search motion.?       Does the same, backwards.n       Repeats the last search in the same directon.N       Repeats the last search in the reverse direction.Extras------*       Search forward for the next instance of the identifier under the cursor.#       Does the same backwards.Marks & Macros=============Marks-----m       Followed by an a-z A-Z character to set a mark.`       Followed by an a-z A-Z character to go to that mark.'       Followed by an a-z A-Z character to go to the first non-blank in that line.`.      Refers to the position of the last modification.Note: A-Z marks are global, a-z per-buffer.Macros------q       Followed by an a-z character to start recording. Use q afterwards to stop recording.@       Followed by an a-z character replays that macro.@@      Repeat the last macro played.Various Motions===============%       Jumps between matching pairs of (),[],{} etc...H,M,L   Jumps directly to the top/middle/bottom of the screen.G       Jumps to the end of the file, or to the line # typed before it.-/+     Jumps to the previous/next line.K       Jumps to the help for the word under the cursor.()      Jumps to the beginning/end of the current sentence.{}      Jumps to the previous/next empty line.[[      Jumps to the previous '{' in column 0.]]      Jumps to the next '}' in column 0.Various Commands================Basics------J       Joins the current line with the next one, or all the lines in the current visual selection.r       Followed by any character replaces the current character with that one.C       The shorthand for c$, change to end of line.D       The shorthand for d$, delete to end of line.Y       The shorthand for yy, yanks the whole line.s       Delete the character under cursor and enters insert mode.S       Clear the current line and enters insert mode.Extras------>       And a motion to indent one or more lines.<       And a motion to unindent one or more lines.>>      Indent 4.<<      Unindent 4.Note: All of them work in visual mode, or can be repeated to operate on the current line.~       Toggles the case of the character under the cursor.


原创粉丝点击