




已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
基礎(chǔ):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剪切、復(fù)制和粘貼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 文本縮進(jìn):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,事實上插入模式下的自動補(bǔ)全功能,那個才真正給力。調(diào)整縮進(jìn) 在插入模式下如果希望調(diào)整行的縮進(jìn),可以返回正常模式,或者調(diào)整縮進(jìn),然后使用i或者a返回插入模式下,要按3次鍵,下面的組合鍵能夠?qū)崿F(xiàn)在插入模式下的縮進(jìn)調(diào)整,每次調(diào)整一個shiftwidth寬度。這個尤其用在寫if之類的縮進(jìn)結(jié)構(gòu)時候,很方便。CTRL+D 減少縮進(jìn)CTRL+T 增加縮進(jìn)復(fù)制相鄰行的內(nèi)容 寫東西的時候經(jīng)常出現(xiàn)相鄰兩行的內(nèi)容很想近的情況,你可以用復(fù)制粘貼功能,也可以直接一個字符一個字符地復(fù)制。CTRL+Y 復(fù)制上一行的相同列的字符CTRL+E 復(fù)制下一行的相同列的字符舉個實際的例子,比如一行內(nèi)容是:num1 is 數(shù)字 在這一行下方新增加一個空白行(插入模式下在行尾回車或者正常模式下按o),光標(biāo)在num1的n正下方,這時候按3下,num被復(fù)制到當(dāng)前位置,輸入數(shù)字2后繼續(xù),空格和漢字也能夠正確被一個一個地復(fù)制下來。粘貼剪貼板 在插入模式下 0-9a-z%#*:=能夠插入剪貼板的內(nèi)容,如果想臨時查看各個剪貼板的內(nèi)容,可以使用:reg,會顯示出各個剪貼板的內(nèi)容。當(dāng)然輸入這個命令很麻煩,做個快捷鍵吧,把下面這句放到你的vimrc里面,當(dāng)然F3可以換成其他功能鍵,這樣你在插入模式下就可以按F3列出所有剪貼板的當(dāng)前內(nèi)容,然后剪貼板名稱吧,這樣做的好處是粘貼完仍然在插入模式下。imap :reg快速移動光標(biāo) 插入模式下快速移動光標(biāo)的命令不太多,除了、到行首、行尾之外,也可以以單詞為單位移動,總比一個字符一個字符移動快一點。或 光標(biāo)左移一個單詞或 光標(biāo)右移一個單詞快速刪除 默認(rèn)情況下Vim在插入模式下只提供了向左刪除的快捷鍵,用不用你自己看著辦吧。CTRL+W 刪除光標(biāo)左側(cè)的單詞CTRL+U 刪除光標(biāo)左側(cè)的行常用命令1.vim#在命令行中輸入vim,進(jìn)入vim編輯器2.i#按一下i鍵,下端顯示 -INSERT-#插入命令,在vim中可能任意字符都有作用3.Esc#退出i(插入)命令進(jìn)行其它命令使用4.:r filename#讀入一個文件內(nèi)容,并寫入到當(dāng)前編輯器中5.:w newfilename#將該編輯器中的內(nèi)容寫入到一個新文件中6.:w#在編輯的過程中保存文件,相當(dāng)于word中的ctrl+s7.:! command暫時離開 vi 到指令列模式下執(zhí)行 command 的顯示結(jié)果!例如:!ls#在編輯過程中執(zhí)行shell命令ls8.:sh#進(jìn)入shell命令行,執(zhí)行完命令后ctrl+d退出重新進(jìn)入vim編輯繼續(xù)編輯在shell命令下,執(zhí)行ctral+l完成清屏9.:wq#保存文件并退出10.ZZ#保存文件并退出,同上一個命令,注意大寫11.:q!#強(qiáng)制退出,不保存12.:set number或者:set nu#使編輯中的文件顯示行號13.:set nonumber或者:set nonu#與上一條命令相反,不顯示行號14.:help i#查看插入命令幫助15.u#撤消上一步操作16./Fedora#查找Fedora字符17.:s /Fedora/Redhat#將Fedora字符替換為Redhat(只替換在光標(biāo)所在的行)18.dw#刪除單詞dd#刪除行19.o#打開空白一行20.vim + filename#進(jìn)行文件最后一行進(jìn)行編輯21.vim +n filename#進(jìn)入文件第n行進(jìn)行編輯22.:1,.s/redhat/fedora#.號表示當(dāng)前行,即光標(biāo)所在行#將第1行到當(dāng)前行(.)第一次出現(xiàn)的redhat字符代替為fedora23.:1,.s/redhat/fedora/g#將第1行到當(dāng)前行(.)所有出現(xiàn)的redhat字符代替為fedora,g全局標(biāo)志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#顯示文件內(nèi)容,狀態(tài)等等#同ctrl+g命令28.:e!#當(dāng)前文件,返回到上次保存:e file#切換編輯文件29.:n#當(dāng)編輯時有多個文件(比如vim file1 file2)時切換到下一個文件,與:e file結(jié)合使用 VIM命令大全光標(biāo)控制命令命令 光標(biāo)移動h 向左移一個字符j 向下移一行k 向上移一行l(wèi) 向右移一個字符G 移到文件的最后一行w 移到下一個字的開頭W 移到下一個字的開頭,忽略標(biāo)點符號b 移到前一個字的開頭B 移到前一個字的開頭,忽略標(biāo)點符號L 移到屏幕的最后一行M 移到屏幕的中間一行H 移到屏幕的第一行e 移到下一個字的結(jié)尾E 移到下一個字的結(jié)尾,忽略標(biāo)點符號( 移到句子的開頭) 移到句子的結(jié)尾 移到段落的開頭 移到下一個段落的開頭0(數(shù)字), | 移到當(dāng)前行的第一列 移到當(dāng)前行的第一個非空字符$ 移到當(dāng)前行的最后一個字符+, Enter 移到下一行的第一個字符- 移到前一行的第一個非空字符在 vi 中添加文本命令 插入動作a 在光標(biāo)后插入文本A 在當(dāng)前行插入文本i 在光標(biāo)前插入文本I 在當(dāng)前行前插入文本o 在當(dāng)前行的下邊插入新行O 在當(dāng)前行的上邊插入新行s 刪除光標(biāo)所在處字符,并進(jìn)入插入模式S 刪除光標(biāo)所在的行,并進(jìn)入插入模式:r file 讀入文件 file 內(nèi)容,并插在當(dāng)前行后:nr file 讀入文件 file 內(nèi)容,并插在第 n 行后Esc 回到命令模式v char 插入時忽略 char 的指定意義,這是為了插入特殊字符在 vi 中刪除文本命令 刪除操作x 刪除光標(biāo)處的字符dw 刪至下一個字的開頭dG 刪除行,直到文件結(jié)束dd 刪除整行db 刪除光標(biāo)前面的字:n,md 從第 m 行開始往前刪除 n 行d, d$ 從光標(biāo)處刪除到行尾h, backspace 插入時,刪除前面的字符w 插入時,刪除前面的字修改 vi 文本每個命令前面的數(shù)字表示該命令重復(fù)的次數(shù)命令 替換操作rchar 用 char 替換當(dāng)前字符R text escape 用 text 替換當(dāng)前字符直到按下 Esc 鍵stext escape 用 text 代替當(dāng)前字符S 或 cctext escape 用 text 代替整行cwtext escape 將當(dāng)前字改為 textCtext escape 將當(dāng)前行余下的改為 textcG escape 修改至文件的末尾ccursor_cmd text escape 從當(dāng)前位置處到光標(biāo)命令位置處都改為 text在 vi 中查找與替換命令 查找與替換操作/text 在文件中向前查找 text?text 在文件中向后查找 textn 在同一方向重復(fù)查找N 在相反方向重復(fù)查找ftext 在當(dāng)前行向前查找 textFtext 在當(dāng)前行向后查找 textttext 在當(dāng)前行向前查找 text,并將光標(biāo)定位在 text 的第一個字符Ttext 在當(dāng)前行向后查找 text,并將光標(biāo)定位在 text 的第一個字符:set ic 查找時忽略大小寫:set noic 查找時對大小寫敏感:ranges/pat1/pat2/g 用 newtext 替換 oldtext:m,ns/oldtext/newtext 在 m 行通過 n,用 newtext 替換 oldtext& 重復(fù)最后的 :s 命令:g/text1/s/text2/text3 查找包含 text1 的行,用 text3 替換 text2:g/text/command 在所有包含 text 的行運行 command 所表示的命令:v/text/command 在所有不包含 text 的行運行 command 所表示的命令在 vi 中復(fù)制文本命令 復(fù)制操作yy 將當(dāng)前行的內(nèi)容放入臨時緩沖區(qū)nyy 將 n 行的內(nèi)容放入臨時緩沖區(qū)p 將臨時緩沖區(qū)中的文本放入光標(biāo)后P 將臨時緩沖區(qū)中的文本放入光標(biāo)前(a-z)nyy 復(fù)制 n 行放入名字為圓括號內(nèi)的可命名緩沖區(qū),省略 n 表示當(dāng)前行(a-z)ndd 刪除 n 行放入名字為圓括號內(nèi)的可命名緩沖區(qū),省略 n 表示當(dāng)前行(a-z)p 將名字為圓括號的可命名緩沖區(qū)的內(nèi)容放入當(dāng)前行后(a-z)P 將名字為圓括號的可命名緩沖區(qū)的內(nèi)容放入當(dāng)前行前在 vi 中撤消與重復(fù)命令 撤消操作u 撤消最后一次修改U 撤消當(dāng)前行的所有修改. 重復(fù)最后一次修改, 以相反的方向重復(fù)前面的 f、F、t 或 T 查找命令; 重復(fù)前面的 f、F、t 或 T 查找命令np 取回最后第 n 次的刪除(緩沖區(qū)中存有一定次數(shù)的刪除內(nèi)容,一般為 9)n 重復(fù)前面的 / 或 ? 查找命令N 以相反方向重復(fù)前面的 / 或 ? 命令保存文本和退出 vi命令 保存和/或退出操作:w 保存文件但不退出 vi:w file 將修改保存在 file 中但不退出 vi:wq 或 ZZ 或 :x 保存文件并退出 vi:q! 不保存文件,退出 vi:e! 放棄所有修改,從上次保存文件開始再編輯vi 中的選項選項 作用:set all 打印所有選項:set nooption 關(guān)閉 option 選項:set nu 每行前打印行號:set showmode 顯示是輸入模式還是替換模式:set autoindent 繼承前一行的縮進(jìn)方式,特別適用于多行注釋:set smartindent 為C程序提供自動縮進(jìn):set list 顯示制表符(I)和行尾符號:set ts=8 為文本輸入設(shè)置 tab stops:set window=n 設(shè)置文本窗口顯示 n 行:set number 顯示行數(shù):set nonumber 取消顯示行數(shù)vi 的狀態(tài)選項 作用:.= 打印當(dāng)前行的行號:= 打印文件中的行數(shù)ctrl+g 顯示文件名、當(dāng)前的行號、文件的總行數(shù)和文件位置的百分比:l 使用字母 l 來顯示許多的特殊字符,如制表符和換行符在文本中定位段落和放置標(biāo)記選項 作用 在第一列插入 來定義一個段落 回到段落的開頭處 向前移到下一個段落的開頭處m(a-z) 用一個字母來標(biāo)記當(dāng)前位置,如用 mz 表示標(biāo)記 z(a-z) 將光標(biāo)移動到指定的標(biāo)記,如用 z 表示移動到 z在 vi 中連接行選項 作用J 將下一行連接到當(dāng)前行的末尾nJ 連接后面 n 行光標(biāo)放置與屏幕調(diào)整選項 作用H 將光標(biāo)移動到屏幕
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 400投訴管理制度
- ab崗位管理制度
- 標(biāo)準(zhǔn)公司財務(wù)管理制度
- 校區(qū)環(huán)境日常管理制度
- 校園內(nèi)網(wǎng)格化管理制度
- 校園學(xué)生常規(guī)管理制度
- 校園戶外設(shè)備管理制度
- 校園河道安全管理制度
- 校園疫情案例管理制度
- 校園超市甲方管理制度
- 2025年河北省萬唯中考定心卷生物(一)
- 2025-2030中國食物病原體檢測行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略分析研究報告
- 托里縣鐵廠溝鎮(zhèn)工業(yè)固廢垃圾填埋場項目環(huán)境影響報告書
- 中草藥種植技術(shù)課件
- 《中國近現(xiàn)代史綱要(2023版)》課后習(xí)題答案合集匯編
- 電磁場與電磁波智慧樹知到課后章節(jié)答案2023年下同濟(jì)大學(xué)
- 最新2022年監(jiān)理工程旁站及平行檢驗項目列表
- 第五單元 曲苑尋珍 丑末寅初 課件(共16張PPT)
- T_CSMPTE 11-2021 電視節(jié)目圖像質(zhì)量主觀評價方法
- 公司工程項目變更索賠組織機(jī)構(gòu)及工作職責(zé)
- 領(lǐng)導(dǎo)干部壓力管理與心理調(diào)適培訓(xùn)講座課件PPT
評論
0/150
提交評論