Vim Cheat Sheet For Programmers Print
Vim Cheat Sheet For Programmers Print
Vim Cheat Sheet For Programmers Print
Normal
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
~ toggle case
!
13
extern filter
1
# 3
prev identifier
3
$ 4
12
% 5
10
goto match
^ 6
soft
& 7
repeat :s
* 8
next identifier
8
( 9
begin sentence
) 0
_ {
0
cur line
+ = } ]
0
autoformat
2
` goto mark
1
14
2 W w S s
7,11
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
half page
Ctrl I
prev mark
ctags identifier
R r
T until char Y t
until char
file/cursor info
U u
15
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
Top screen
J j
15
Join lines
| \
goto col#
a append Z z
quit extra
g B b
Ctrl M
Ctrl ,
Ctrl .
Ctrl ^ Shift
:suspend
4 5
Normal / Cancel
X x
change change
0 2
WORD word
N n
M m
> .
? /
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.
Start of Line 1st non-whitespace Diff hard [c prev diff :hi Start of Line column 0 ]c next diff :hi End of Line :help modes #| move col # :diffupdate :hi move col 0 ^f page :hi Esc ^[ ^c Normal page resync ^d page a i r s Insert page Folding v V ^v ^q Visual scroll line ^y scroll line 0g end of file zR fold remove c d y < > Op pending start of file G end of file zo fold open Command Line : / ? ! goto line # Foo ( src , dst , len ); zc fold close begin this func { zi invert all Note: There is no whitespace in-between 'Foo(src,' but before/after 'dst,' begin next func { zr fold reduce Foo ( src , dst , len ); WORD :set matchpairs=(:),{:},[:],<:>,?:\: % goto matching { } < > [ ] zm fold more Startup vim <filename> +123 :help range goto line 123 vim <file> -t Foo :s/Foo/Bar edit at tag 'Foo' find Foo replace w/ Bar :help recording 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 .,.+# cur line, cur line + # lines GUI Linux :set guifont=ProggyTinyTT\ 12 q stop recording GUI OSX :set guifont=ProggyTiny\:h11 $ last line '< start of select @@ repeat '> end of select diff gvimdiff <file1> <file2> [<file3>] bug = < > << >> :set tabstop=# Broken Keys Ctrl-I = Tab, Ctrl-[ = ESC Code
soft
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 ' " `
:help cmdline :r file insert file Tags :w save :gui switch to GUI :ts :q quit :q! quit w/o save ^] :e <file> edit file in new buffer ^t :source % exec cmds in cur file ^p :exec '...' do cmd :ta Foo
:help movement ^ 0 $ | ^b ^u ^e 1g #g [[ ]]
list active tags jump to tag under cursor restore cursor before tag jump complete word manual jump to tag 'Foo'
DiffAdd
guifg=#rrggbb
DiffChange guibg=#rrggbb
Changes
:changes g; older change g, newer change
Syntax
:syntax enable :set filetype=
Convert <eol>
:set fileformat=
Vim is still unable to map certain keys for your own use
:set backspace=indent,eol,start
:set expandtab!
Caps, Ctrl-1, Ctrl-Shift-1, Ctrl-I, Ctrl-\, etc. 0 See: src/ops.c -c "/valid_yank_reg" for " reg. names 6 See: src/normal.c -c "/nv_cmds" for g extra cmds 11 See: src/edit.c -c "/ctrl_x_msgs" for ^x insert cmds
allow backspace join lines :set listchars= :set shiftwidth=# indent width for ai :set list!
:set autoindent! toggle auto-indent :set lisp lisp indent mode
unix or dos or mac then :w to convert set tab stop every #th col toggle hard/soft tabs tab:>-:trail:-,nbsp:%,eol:$ toggle whitespace block comment
noremap + :s/^/\/\//<CR>
\ :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 files :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. :vsplit vertical :only maximize all same size move to win move to win move to win move to win [<filename>]
File / Directory
:Explore or :e . :set browsedir= one of buffer last