move hjkl ctrl-f page up ctrl-b page down gg * go to first line % jump to matching brace w jump to next word W jump to next blank delimited word e * jump to end of word E jump to end of blank delimited word b * jump to the beginning of the word B jump to the beginning of blank delimited word 0 * start of line ^ first character of line $ end of line gd go to def of the function or var under the cursor gD go to def of the file or var g_ * go to non-blank character end of line G * go to last line :n go to line n fx * move the cursor forwards to the next occurrence of character x on the current line tx like fx, move right before the character ),( move the cursor to the next,previous sentence * read the string under the cursor and go to next occurrence # same as *, but goes previous occurrence '. go to line last edit g, * go to last edit m mark, ma-mark a line, then 'a, go to thi line HML cursor go to highest,middle,lowest of screen zz,zt,zb let the cursor line go to middle,top,bottom of the screen,z + go to the beginning of next line - go to the beginning of last line '' * last mark, such as gd, * '. * last modify line `. last modify poin
在vim中自由的寻找
# next identifier * prev identifier g# * search the word cursor locate, and allow the word is a part of a word,previous g* search the word cursor locate, and allow the word is a part of a word,next / search forward by string ? search back by string n find matched word next one N find matched word previou one /GO\c * find go or Go, ignore up and down q/ show history of find command q? show and use history of find command /joe/e cursor set to end of match 3/joe/e+1 find 3rd joe cursor set to end of match plus 1 /joe/s-2 cursor set to start of match minus 2 :g/start/# * show the line which is matched /jo[ha]n * search john or joan /\<the search the, theatre or then, the is the beginning of the word /the\> search the or breathe, the is the end of the word /\<the\> * search the, exactly matched /fred\|joe * search fred or joe /\<\d\d\d\d\> * search exactly 4 digits /^\n{3} find 3 empty line
在vim中增,删,改,查中的删
Delete x * delete current character X delete previous character C * cut to end of line and insert character D delete to the end of line s * delete character at cursor and substitute text S delete line at cursor and substitute text 3dd delete 3 lines 3cc cut 3 lines and edit yy * copy current line dd * delete current line dG * deletet to the last line yG copy from cursor to last line 3yy copy 3 lines p put the clipboard after cursor/current line P put the clipboard before the cursor/current line r replace a single character R replace mode from here y2w copy two word d2w delete two word db delete head of word da>,da<,da(,da),da{,da} delete <>,().{} di>,di<,di(,di),di{,di} delete contnet of <>,().{} ce change to end of word and go to insert mode cw change word and go to insert mode c3w change 3 word and go to insert mode d/foo delete foo backwards y?bar copy the first bar appear y2/foo copy the string from cursor to the 2nd foo appear d/fred/ delete until fred y/fred/ yank until fred c/fred/e change until fred end "*yy copy current line to system clipboard "*p paste system clipboard to current line :%s/*$//g delete all white spaces :g/string/d * delete all lines containing string :v/string/d delete all lines containing which didin't contain string :g/^s*$/d delete all blank lines :g!/^dd/d delete lines not containing string :v/^dd/d delete line not containing string :g/joe/,/fred/d * not line based(very powerfull) :g/fred/,/joe/j join lines[N
vim 中增,删,改,查中的改
Edit i insert mode at cursor I insert at the beginning of line a * append after the cursor A * append at the end of the line s * delete character at cursor and substitute text S delete line at cursor and substitute text o * open blank line below current line O open blank line above current line r replace a single character J join line below t the current line cc * change an entire line c$ change to the end of line cw change to end of the word . repeat last command ~ switch case fa go to first a location guw * change to the end of word to lowercase guiw change word to lowercase gUw * change to the end of word to uppercase gUiw hange word to uppercase guu * change word line to lowercase gUU * change word line to uppercase
vim的强大替换
replace :%s/old/new/g * replace al occurences of old by new in file :%s/old/new/gc replace all occurences with confirmation :2,35/old/new/g replace all occurences btween 2,35 line :5,$s/old/new/g replace all occurences from line 5 to EOF :%s/^/hello/g replace the beginning of each line by hello :%s/$/Harry/g replace the end of each line by Harry :%s/onward/forward/gi replace onward by forward, case unsensitive:s/bill/steve/ replace the first occurence of bill by steve in current line :s/bill/steve/g replace bill by steve in current line :%s/bill/steve/g replace bill by steve in the whole file :%s/\r//g delete DOS carriage :%s/\r\r/g transform DOS carriage returns in returns :%s#<[^>]\+>##g delete HTML tags but keep text :%s/^\(.*\)\n\1$/\1/ delete lines which appear twicevisual mode
v V viB choose code between { } vaB choose code contain { } vib choose code between ( ) vab choose code contain ( ) viw choose word vaw choose one word ctrl-v/ctrl-q choose block ctrl-v-I-ESC * insert character before block ctrl-v-A-ESC * insert character after block ctrl-v-C-ESC change character block ctrl-v-> left indent block ctrl-v-r replace character block in each linefolder
zf F-old creation zo * open folder zc * collapse folder zm more collapse folder by one level zM more collapse folder until have no left zr open folder by one level zR open folds until there are none lefmultifile
:histshow history :ls show files in the buffer ctrl-6 * switch buffer file :bn * buffer next :bp * buffer previous :b number buffer number e: file edit a file in a new buffer :bn go to next buffer :bd delete a buffer (close file) :sp fn open a file in new buffer and split window ctrl-w s split window ctrl-w w switch window ctrl-w q quit window ctrl-w v split windows vertically tabe filename edit file in new tab gt * next tab gT * previous tabs :tabr First tab :tabl last tab :tabm[N] move current tab after tabmarco and register
"ayy copy current line to register a "Ayy copy current line to register a, >> "ap paste a "bp paste b :reg display contents of all register :reg a display contents of register a qqq empty register "q" qaq empty register "a qa start marco recording q finish recording @a execute the marco a @@ execute the last marco 5@@ execute 5 times last marco executiocoding indent
coding indent < viB-< decrease indent > viB-> increment indent <iB,>iB,<aB,>aB * indent block directly >i{ move not contain { >%,<% move contain { =% auto indent in {} ctrl-n/ctrl-p * complement :abbr terry [email protected] input terry is input [email protected] get external input :r!<cmd> * put cmd's content insert to the file :r <file> * put file's content to the fil :!dir execute dir command in the system :w filename save as filename :wq save and quit参考:
http://coolshell.cn/articles/5426.html http://www.360doc.com/content/15/0103/20/21332217_437804813.shtml http://www.360doc.com/content/12/0529/15/7630019_214508863.shtml http://www.360doc.com/content/14/0410/00/12129652_367644230.shtml http://www.360doc.com/content/07/0530/13/1429_529097.shtml http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip15// http://blog.csdn.net/ubuntu_hao/article/details/14100939