You are on page 1of 1

Esc

Normal

Revision 2.0 Sept. 11, 2011

Vim 7.3+ :version

Vim Cheat Sheet for Programmers


Search :set incsearch ignorecase smartcase hlsearch Ctrl 7 Ctrl 8 Ctrl 9

Copyleft 2011
May be freely distributed! Sharing is Caring.

http:/michael.PeopleOfHonorOnly.com/vim/

HOW-TO make Vim not suck Out of the Box: :help statusline :set nocompatible ruler laststatus=2 showcmd showmode number

Remove useless splash screen :set shortmess+=I :map <F6> :so $HOME/_vimrc<CR> Ctrl _ Ctrl = Ctrl 0

Best tips: http://vim.wikia.com/


Ctrl ` Ctrl 1 Ctrl @

Best scripts: http://www.vim.org/scripts/index.php


Ctrl 3 Ctrl 4 Ctrl 5 Ctrl ^ play macro

:map <F9> :e $HOME/_vimrc<CR>

~ toggle case ` goto mark


13

! 1
14

extern filter
1

# 3

prev identifier
3

$ 4
12

:redo Replace replace char page

% 5
10

goto match

^ 6

soft

& 7

repeat :s

* 8

next identifier
8

( 9

begin sentence

) 0

end sentence hard


9

_ {
0

cur line

+ = } ]
0

autoformat
2

2 W w S s
7,11

Normal paragraph misc.


Ctrl '

block select ^w window

Q
Tab

ex mode
record macro

WORD word

E e
10

q
7

scroll line end WORD end word half page del del
0 2

ctags return

scroll line copy line copy


Ctrl H
0 2

half page

Ctrl I

prev mark

ctags identifier

R r

T until char Y t
until char
file/cursor info

U u
15

undo line undo


Ctrl J

I insert O open P i K k < ,


insert

paste paste
Ctrl ;

paragraph misc.
Ctrl \

y H h
9,16

o L l
2

incr. # subst line subst char decr. # del char del char

open
redraw Bottom screen

p : ;
2

[ " '

A append
Caps

D d C c

F find char G f V v
find char
block select

goto eof / goto line# extra page


6

Top screen

J j
15

Join lines

man page identifier

cmd line "next" f/F/t/T


Ctrl /
16

register

| \

goto col#

a append Z z
quit extra

g B b

"prev" find find "next"

Ctrl M

Ctrl ,

Ctrl .

goto mark

Ctrl ^ Shift

:suspend
4 5

Normal / Cancel

X x

change change
0 2

select lines select chars

WORD word

N n

M m

Middle screen set mark

undent "prev" f/F/t/T

> .

indent repeat cmd

? /

find find

16

Unused & Duplicate keys \ Ctrl-K Ctrl-S (free) Ctrl-L (redraw) 13 ` near dup of ' 14 Ctrl-Q = Ctrl-V 15 Ctrl-J = Ctrl-M = ^N

Legend:
Macro

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.

:help cmdline :r file insert file :help tags :w save :gui switch to GUI :ts list active tags :q quit :q! quit w/o save ^] jump to tag under cursor :e <file> edit file ^t restore cursor before tag jump :source % exec cmds in cur file ^p complete word :exec '...' do cmd :ta Foo manual jump to tag 'Foo' :help movement soft ^ Start of Line 1st non-whitespace :help diff :hi DiffAdd guifg=#rrggbb hard 0 Start of Line column 0 [c prev diff :hi DiffChange guibg=#rrggbb $ End of Line ]c next diff :help modes | move col 0 #| move col # :diffupdate :hi DiffText gui=none ^b page ^f page :hi DiffDelete Esc ^[ ^c Normal resync ^u page ^d page a i r s Insert ^e scroll line ^y scroll line v V ^v ^q Visual :help folding :help changes 1g start of file 0g end of file zR fold remove :changes c d y < > Op pending #g goto line # G end of file zo fold open g; older change Command Line : / ? ! Foo ( src , dst , len ); [[ begin this func { zc fold close g, newer change ]] begin next func { zi invert all Note: There is no whitespace in-between 'Foo(src,' but before/after 'dst,' zr fold reduce Foo ( src , dst , len ); :help syntax WORD :set matchpairs=(:),{:},[:],<:>,?:\: % goto matching { } < > [ ] zm fold more :syntax enable Startup vim <filename> +123 :set filetype= goto line 123 :help range vim <file> -t Foo :s/Foo/Bar edit at tag 'Foo' find Foo replace w/ Bar :help recording c cpp sh make perl python Note: chose only ONE type! vim <file> -c "/Foo" cmd: find 'Foo' & edit :s/Foo/Bar/g ...all instances on line q start recording GUI vim -g gvim :%s/Foo/Bar @ playback or start GUI ver. apply to whole file convert <eol> .,.+# cur line, cur line + # lines GUI Linux :set guifont=ProggyTinyTT\ 12 q stop recording :set fileformat= GUI OSX :set guifont=ProggyTiny\:h11 $ last line '< start of select @@ repeat unix or dos or mac '> end of select diff gvimdiff <file1> <file2> [<file3>] then :w to convert bug :set tabstop=# Broken Keys Ctrl-I = Tab, Ctrl-[ = ESC set tab stop every #th col Code = < > << >> :set backspace=indent,eol,start :set expandtab! Vim is still unable to map certain keys for your own use toggle hard/soft tabs Caps, Ctrl-1, Ctrl-Shift-1, Ctrl-I, Ctrl-\, etc. allow backspace join lines :set listchars= tab:>-:trail:-,nbsp:%,eol:$ :set shiftwidth=# indent width for ai :set list! 0 See: src/ops.c -c "/valid_yank_reg" for " reg. names toggle whitespace :set autoindent! toggle auto-indent :set colorcolumn=80 visible right margin indicator 6 See: src/normal.c -c "/nv_cmds" for g extra cmds :set lisp 11 See: src/edit.c -c "/ctrl_x_msgs" for ^x insert cmds lisp indent mode noremap + :s/^/\/\//<CR> block comment Op Cmd Ins Move Find tag Code Extra Modes n i v o c word

Register name (0-9a-zA-Z) required Motion req.; act between cursor & dst Command Command and enter insert mode Moves cursor or defines range for op Search ( = reverse, = forward) ctags / diffs / folding Code formatting, whitespace, etc. Extended functionality; req. extra chars Char arg req. g z Z ^w ' " `

\ :map \ :Explore<CR> manually type <,C,R,> 0 " before del/copy/paste to use register "+x cut to system clipboard reg. '+' "+gP paste from system clipboard 1 Number before any action repeats it 2p 3. repeat thrice paste twice 2 Repeat op to act on current line yy dd del line copy line << >> indent line undent line 3 # highlight words under cursor ZQ quit w/o save 4 ZZ save & quit 5 zz center cursor line in window zh zl scroll right scroll left zt zb scroll bottom scroll top 6 gg top of file gf open file under cursor 7 ^a incr # under cursor (Dec / Hex) ^x decr # under cursor (Dec / Hex) 8 * start a "new" search Insert mode 9 ^p prev auto-complete ^n next ^t 10 ^d undent indent 11 ^x ^f filename completion ^s spelling :set spell! ^k dictionary ]s next bad ^t thesaurus :help spell 12 ^r paste register 0-9a-zA-Z or + clipboard (or '*') :help c_CTRL-R " last del/copy % filename :set numbers! toggle line numbers :set wrap! toggle linewrap display :set showmatch highlite matching () noremap - :s/^\/\///<CR> uncomment

:buffer #
:buffers list :new blank file/buffer :bn next file :bp prev file :bd close file :bd! force close :set lines=# :set columns=# :winpos # # GUI

Windows
:help windows ^w or :wincmd w! c! n! s! v! o! =! h! j! k! l! ! :sp :switch to next :close! :new :split horz. horz. :vsplit vertical :only maximize all same size move to win move to win move to win move to win [<filename>]

edit in split window Cursor Bookmarks


:marks ` ' ^o ma mark local 'a' 'A goto global 'A' '' prev location

File / Directory
:Explore or :e . :set browsedir= one of buffer last

You might also like