linux--VIM命令大全.docx_第1頁
linux--VIM命令大全.docx_第2頁
linux--VIM命令大全.docx_第3頁
linux--VIM命令大全.docx_第4頁
linux--VIM命令大全.docx_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

基礎: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 系統(tǒng)交互:!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次鍵,下面的組合鍵能夠實現(xiàn)在插入模式下的縮進調整,每次調整一個shiftwidth寬度。這個尤其用在寫if之類的縮進結構時候,很方便。CTRL+D 減少縮進CTRL+T 增加縮進復制相鄰行的內容 寫東西的時候經常出現(xiàn)相鄰兩行的內容很想近的情況,你可以用復制粘貼功能,也可以直接一個字符一個字符地復制。CTRL+Y 復制上一行的相同列的字符CTRL+E 復制下一行的相同列的字符舉個實際的例子,比如一行內容是:num1 is 數(shù)字 在這一行下方新增加一個空白行(插入模式下在行尾回車或者正常模式下按o),光標在num1的n正下方,這時候按3下,num被復制到當前位置,輸入數(shù)字2后繼續(xù),空格和漢字也能夠正確被一個一個地復制下來。粘貼剪貼板 在插入模式下 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 到指令列模式下執(zhí)行 command 的顯示結果!例如:!ls#在編輯過程中執(zhí)行shell命令ls8.:sh#進入shell命令行,執(zhí)行完命令后ctrl+d退出重新進入vim編輯繼續(xù)編輯在shell命令下,執(zhí)行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行到當前行(.)第一次出現(xiàn)的redhat字符代替為fedora23.:1,.s/redhat/fedora/g#將第1行到當前行(.)所有出現(xiàn)的redhat字符代替為fedora,g全局標志24.:1,$s/redhat/fedora/g#$表示最后一行#將第1行到最后一行所有出現(xiàn)的redhat字符代替為fedora25.:%s/redhat/fedora/g#同上一個命令26.:%s/fedora/g#將第1行到最后一行所有出現(xiàn)的redhat字代替為fedora#字,而不是字符27.:f#顯示文件內容,狀態(tài)等等#同ctrl+g命令28.:e!#當前文件,返回到上次保存:e file#切換編輯文件29.:n#當編輯時有多個文件(比如vim file1 file2)時切換到下一個文件,與:e file結合使用 VIM命令大全光標控制命令命令 光標移動h 向左移一個字符j 向下移一行k 向上移一行l(wèi) 向右移一個字符G 移到文件的最后一行w 移到下一個字的開頭W 移到下一個字的開頭,忽略標點符號b 移到前一個字的開頭B 移到前一個字的開頭,忽略標點符號L 移到屏幕的最后一行M 移到屏幕的中間一行H 移到屏幕的第一行e 移到下一個字的結尾E 移到下一個字的結尾,忽略標點符號( 移到句子的開頭) 移到句子的結尾 移到段落的開頭 移到下一個段落的開頭0(數(shù)字), | 移到當前行的第一列 移到當前行的第一個非空字符$ 移到當前行的最后一個字符+, 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 文本每個命令前面的數(shù)字表示該命令重復的次數(shù)命令 替換操作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 將當前行的內容放入臨時緩沖區(qū)nyy 將 n 行的內容放入臨時緩沖區(qū)p 將臨時緩沖區(qū)中的文本放入光標后P 將臨時緩沖區(qū)中的文本放入光標前(a-z)nyy 復制 n 行放入名字為圓括號內的可命名緩沖區(qū),省略 n 表示當前行(a-z)ndd 刪除 n 行放入名字為圓括號內的可命名緩沖區(qū),省略 n 表示當前行(a-z)p 將名字為圓括號的可命名緩沖區(qū)的內容放入當前行后(a-z)P 將名字為圓括號的可命名緩沖區(qū)的內容放入當前行前在 vi 中撤消與重復命令 撤消操作u 撤消最后一次修改U 撤消當前行的所有修改. 重復最后一次修改, 以相反的方向重復前面的 f、F、t 或 T 查找命令; 重復前面的 f、F、t 或 T 查找命令np 取回最后第 n 次的刪除(緩沖區(qū)中存有一定次數(shù)的刪除內容,一般為 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 顯示行數(shù):set nonumber 取消顯示行數(shù)vi 的狀態(tài)選項 作用:.= 打印當前行的行號:= 打印文件中的行數(shù)ctrl+g 顯示文件名、當前的行號、文件的總行數(shù)和文件位置的百分比: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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論