Revision 2.0 Mm7.3+ Vim Cheat Sheet for Programmers Copyleft 2011 ESC Normal Scpt.11.2011 Iversion suck Out of the Box: help st拉t beh2h0 Search set incsearch ignorecase smartcase hisearch splash screen :set shortmess+l Best tips: http://vim.wikia.com/ Best scripts: http://www.vim.org/scrpts/index.php virc.CRs CH c42 C44 CHi5 Ch= toggle case @ prev goto soft- next begin end cur line macro identifier % match repeat:s identifier sentence sentence goto mark 2 3 4 5 6 7 8 0 auto. 9 hard- format block select w window... scroll line scroll line half page t GH+ prev mark Normai cags iemfs ex mode W WORD E end Replace T.until char copy line U undo line insert WORD open T paste paragraph paragraph record end replace macro W word e until char char copy undo tinsert open paste misc. misc. word 7 incr. 1o half page l page I fleloursor ino 合样4 15 G redraw Ci Cirk Gif- A append s subst line D del- F +fnd char G goto eof/ H Join lines K man page Bottom Ex cmd line register goto line# Top screer identifier screen goto cols a append "next" subst char goto mark d del f find char g extra ↑ UFIT suspend 7,1t deci慕 block sefedt page↑ 1超 C/ Unused Duplicate keys Middle cerl-K Ctrl-8 (free) quit X -del cha c select change WORD N "prev' Indent lines find M undent nd screen 13Ctrl-L (redeau) near dup of 2 del char select word find pre☑ extra change set mark repeat find 4CErl-0 ctrl-V X m chars "next" t/F/t/ cmd 5Cte1-J■Ctg1-M■“围 ection find. Register name (0-9a-zA-Z)required :help cmdline 1 e insert file help tags manualy type :bufter Op Motion reg-;act between cursor dst :w save 9 switch to lst active tags obefore deloopy/paste to use register Cmd Command quit qut wo save 1 ump to tag under cursor cut to system clipboard reg.' nev blank file/buffe Command and enter insert mode edit file in new buffer restore cursor before tag jump -+gB paste from system clipboard bn next fle Move Moves cursor or defines range for op :source 1 exec cmds in cur file complete word 1Number before any action repeats it bp prev file Find Search (reverse,=forward) exec '...do cmd aroo manual jump to tag 'Foo' paste twice 3.repeat thrice :b4close file tag ctags diffs folding help movement 2 Repeat op to act on current line ba force close Code Code formatting,whitespace,etc. *Start of Line 1on-wh403c全 help diff copy line aa del line :每世光】五e组4 Extra Extended functionality:req.extra chars oStart of Line column 0 [e prev ditf th4D1fEd日 qulfg-lregghb undent line ≥>ndent line :8e生心后1u的n参m Char arg req- End of Line le next diff :hi Diffchange cuibg"lrrggbb 3 highlight words under cursor :wimpos Modes thelp modes move col 0 move col :diEf和odate :hI DIffrext quimnose 4 save quit so quit wio save Windows n Nommal page↑ "r page↓ resync 5 center cursor line in window :help windovs Insert u⅓page t 4⅓page1 scroll left a1 scrol right Visual "e scroll line y scroll line! help folding help changes scroll top bscroll bottom switch to next Op pending c d y ,? ar fold reduce help syntax 8 start a "new"search Startup goto matching(<>[] fold more y告te山1 Insert mode move to win move to winI goto line 123 help range 生et ri1 ctype- 90 prev auto-complote"a next 104 nove to win vis --t Foo edit at tag 'Foo' /Poe/Ba正 find Foo replace w Bar chelp recording cpp sh make perf python undent Indent y n灯eon4 via cfile>_-e "/Yoo" cmd:find 'Foo'&edit s/Foo/Bar/g .all instances on line 9 start recording Note:chose only ONE typel st生filename completion sp [cfilenane>] vis -u or evin start GUl ver. is/96o/Bae apply to whole file playback convert spelling iset spelll edit in split window Linux :set gulfost"ProggyrisyTr\12 cur line,cur line+#lines stop recording set且lef0raat■ k dictionary next bao Cursor Bookmarks OSXt3et91fa地t■Pog到yT1y\:h11 last line 's start of select repeat unix or dos or mac ethesaurus thalp spell o9N vd1f4 >end of select then w to convert 12 paste register 0-9-ZA-Z or... mark local 'a' Broken Keys Co Too Ciif-ESc Code set tab stop every #th co clipboard (or):help e_crm goto global'A' Vim is stw unablle to map certain keys for your awn use.. :set expand生ab toggle hard/soft tabs last delcopy filename orev ocaton Caps,Ctr-1,Ctrf-Shit-1.Carhl Cartl etc. allow backspace join lines tab.>-trait-.nbsp.%eol$ toggle line numbers File Directory See:sre/eps.c -"/valid_yusk rug"for reg.names aet indent width for ai toggle whitespace 每et werap! toggle linewrap display Explore or te 6 See:are/eoreal.c -"/mv_enda"forg extra cmds set autoladeet!toggle auto-indent :t colereole=n-so visible right margin indicator :set showmatch highlite matching :Bet凸e程e通且■ 11 See sse/edit.s -/etr1_x_miga for insert cmds lisp indent mode Borenap+s/-八八/block comment noremap-ts/\/八//<c uncomment one of burror last
HOW-TO make Vim not suck Out of the Box: :help statusline :set nocompatible ruler laststatus=2 showcmd showmode number Search :set incsearch ignorecase smartcase hlsearch Remove useless splash screen Best tips: http://vim.wikia.com/ Best scripts: http://www.vim.org/scripts/index.php :map :e $HOME/_vimrc :map :so $HOME/_vimrc ~ ! # $ % ^ & * ( ) _ + `• 13 1 2 3 3 4 5 6 7 8 8 9 0 - = 2 14 ^w• 12 10 9 E R T• Y U I O P { } e r t• y 0 2 u i ↱insert o p 0 [• ]• 7 10 15 D F• G H J K L : "• 0 | append d 0 2 f• g• 6 h j k l ; 16 '• \• \ Ctrl ^ 7,11 9,16 15 Unused & Duplicate keys Shift ⇧ 13 14 15 Legend: 16 The search direction is relative; next is the initial direction, previous is the opposite direction. n ; repeat same initial direction find. N , repeat opposite initial direction find. Note: ; , only searches cursor line, n N searches buffer. Register name (0-9a-zA-Z) required :r file insert file \ :map \ :Explore manually type Motion req.; act between cursor & dst :w save :gui switch to GUI :ts list active tags §0 "• before del/copy/paste to use register :buffers list Command :q quit :q! quit w/o save ^] jump to tag under cursor "+x cut to system clipboard reg. '+' blank file/buffer Command and enter insert mode :e edit file in new buffer ^t restore cursor before tag jump "+gP paste from system clipboard :bn next file Moves cursor or defines range for op :source % ^p complete word 1 Number before any action repeats it :bp prev file Search (↖ = reverse, ↘ = forward) :exec '...' do cmd :ta Foo manual jump to tag 'Foo' 2p paste twice 3. repeat thrice :bd close file ctags / diffs / folding 2 Repeat op to act on current line :bd!force close Code formatting, whitespace, etc. soft ^ ⇤ Start of Line 1st non-whitespace yy copy line dd del line :set lines=# Extended functionality; req. extra chars hard 0 ⇤ Start of Line column 0 [c prev diff > indent line :set columns=# Char arg req. $ ⇥ End of Line ]c next diff 3 # highlight words under cursor :winpos # # GUI :help modes | move col 0 #| move col # :diffupdate :hi DiffText gui=none 4 ZZ save & quit ZQ quit w/o save n Normal Esc ^[ ^c ^b page ↑ ^f page ↓ resync :hi DiffDelete 5 zz center cursor line in window :help windows i Insert a i r s ^u ½ page ↑ ^d ½ page ↓ zh scroll left zl scroll right ^w• or :wincmd • v Visual v V ^v ^q ^e scroll line ↑ ^y scroll line ↓ zt scroll top zb scroll bottom o Op pending c d y 1g start of file 0g end of file zR fold remove :changes §6 gg top of file c Command Line : / ? ! #g goto line # G end of file zo fold open g; older change gf open file under cursor word ( src , ␢ , ␢ len ); [[ begin this func { zc fold close g, newer change 7 ^a incr # under cursor (Dec / Hex) ]] begin next func { zi invert all ^x decr # under cursor (Dec / Hex) WORD Foo ( src , ␢ , ␢ len ); :set matchpairs=(:),{:},[:],,?:\: zr fold reduce 8 * start a "new" search Startup % goto matching { } [ ] zm fold more :syntax enable vim +123 goto line 123 :set filetype= ^p ^n next vim … -t Foo edit at tag 'Foo' :s/Foo/Bar find Foo replace w/ Bar c cpp sh make perl python ^d undent ^t indent vim … -c "/Foo" cmd: find 'Foo' & edit :s/Foo/Bar/g ...all instances on line q• start recording Note:&chose&only&ONE&type! ^x• ^f filename completion :sp [] GUI vim -g or gvim start GUI ver. :%s/Foo/Bar apply to whole file @• playback ^s spelling :set spell! edit in split window GUI Linux :set guifont=ProggyTinyTT\ 12 cur line, cur line + # lines q stop recording :set fileformat= ^k dictionary ]s next bad GUI OSX :set guifont=ProggyTiny\:h11 $ last line ' [] '> end of select then :w to convert ^r• paste register 0-9a-zA-Z or … ma mark local 'a' bug Broken Keys Ctrl-I = Tab, Ctrl-[ = ESC = > :set tabstop=# set tab stop every #th col + clipboard (or '*') 'A goto global 'A' Vim is still unable to map certain keys for your own use… :set backspace=indent,eol,start :set expandtab! toggle hard/soft tabs " last del/copy % filename '' prev location § Caps, Ctrl-1, Ctrl-Shift-1, Ctrl-I, Ctrl-\, etc. allow backspace join lines :set listchars=… tab:>-:trail:-,nbsp:%,eol:$ :set numbers! toggle line numbers 0 See: src/ops.c -c "/valid_yank_reg" for "• reg. names :set list! toggle whitespace :set wrap! toggle linewrap display :Explore or :e . 6 See: src/normal.c -c "/nv_cmds" for g• extra cmds :set autoindent! :set showmatch highlite matching () 11 See: src/edit.c -c "/ctrl_x_msgs" for ^x• insert cmds :set lisp lisp indent mode noremap + :s/^/\/\// block comment noremap - :s/^\/\/// uncomment one of buffer last :help cmdline A a :help range §11 :hi DiffAdd guifg=#rrggbb :hi DiffChange guibg=#rrggbb .,.+# :help c_CTRL-R Insert mode 10 12 :help folding 9 dst Z• z• :help movement set mark M m• quit 4 extra Ctrl 3 prev identifier Tab Caps goto mark incr. # extern filter append ⇥ end WORD ↘ subst line subst char scroll line ↑ del ⇥ del @• play macro W w half page ↓ end word ↘ ↖ word N n "prev" find find "next" undo line q• undo Q Normal / Cancel block select find char → extra replace char ← find char page ↑ page ↓ Middle B screen ↖ WORD 5 ← del char C del char → c change b 0 2 change ⇥ V select lines select chars v dst http:/michael.PeopleOfHonorOnly.com/vim/ Copyleft&©&2011 May&be&freely&distributed! Sharing&is&Caring. paragraph ↘ autoformat Ctrl ; paste ⤒ ↖ paragraph misc. redraw open ⤒ open ⤓ prev mark Ctrl ' Ctrl = , ctags identifier misc. :redo paste ⤓ ↑ Ctrl 4 Ctrl 5 Ctrl _ Ctrl I Normal soft ⇤ next identifier copy ⇥ repeat :s insert ⇤ ctags return ← until char until char → scroll line ↓ copy line half page ↑ Replace Ctrl M Ctrl , Ctrl H Ctrl J goto mark ⇤ register Bottom screen ← ↓ ↓ Top screen man page identifier "next" f/F/t/T Join lines Extra tag Find :set shortmess+=I begin sentence Ctrl ^ Ctrl 7 Ctrl 8 Ctrl 9 Ctrl 0 goto match ⇤ goto col# Ctrl \ hard ⇤ end sentence cur line ↑ ↓ Ex cmd line file/cursor info goto eof / goto line# indent 2 ?• find ↖ . repeat cmd /• find ↘ :buffer # Windows Cursor Bookmarks File / Directory :new "prev" prev auto-complete f/F/t/T 16 Normal Vim 7.3+ :version Ctrl 1 x 1 record macro window… WORD ↘ word ↘ decr. # Ctrl ` Ctrl @ :suspend ↰ s toggle case S block select ex mode X Esc Revision 2.0 Sept. 11, 2011 :set shiftwidth=# indent width for ai toggle auto-indent visible right margin indicator Modes Macro Cmd Code • :set colorcolumn=80 Ins Move Op exec cmds in cur file g z Z ^w ' " ` … :help diff :help tags Code :help syntax :help changes convert :help recording Note: There is no whitespace in-between 'Foo(src,' but before/after 'dst,' Foo w c n s v o = h j k l :switch to next :close! :new :split horz. :vsplit vertical :only maximize all same size move to win ← move to win ↓ move to win ↑ move to win → Vim Cheat Sheet for Programmers w c n s v o = h j k l :switch to next :close! :new :split horz. :vsplit vertical :only maximize all same size move to win ← move to win ↓ move to win ↑ move to win →