Vim Cheat Sheet For Programmers Screen
Vim Cheat Sheet For Programmers Screen
Normal
Revision 1.99
Sept. 9, 2011
Copyleft
2011
May
be
freely
distributed! Sharing
is
Caring.
HOW-TO make Vim not suck Out of the Box: :help statusline :set nocompatible ruler laststatus=2 showcmd showmode number
Ctrl 7
Ctrl 8
! 1
14
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
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
register
| \
goto col#
a Z z
append
g B b
Ctrl M
Ctrl ,
Ctrl .
goto mark
Ctrl ^ Shift
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.
:help cmdline :help tags :gui switch to gui GUI :ts list active tags :q! quit w/o save ^] jump to tag under cursor ^t edit file restore cursor before tag jump ^p exec cmds in cur file complete word :ta Foo manual jump to tag 'Foo' do cmd :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
:w save :q quit :e <filename> :source % :exec '...'
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. :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= buffer last