Sep 11, 2011 - blank file/buffer. Command and enter insert mode. :e edit file. ^t .... stop recording :set
Vim 7.3+ :version
Revision 2.0 Sept. 11, 2011
Normal
HOW-TO make Vim not suck Out of the Box: :help statusline :set nocompatible ruler laststatus=2 showcmd showmode number
Best tips: http://vim.wikia.com/ Ctrl `
!
~ toggle case `• goto mark
13
Ctrl 5
extern filter
play macro
prev identifier
⇥
goto match
Shift ⇧
@•
2
#
block select ^w• window…
ex mode
W
WORD ↘
E
q•
record macro
w
word ↘
e
7
incr. #
10
scroll line ↑ end WORD ↘ end word ↘
S
subst line
D
del ⇥
a append
s
subst char
d
del
7,11
decr. #
Z•
quit
z•
extra
4 5
4 12
Search :set incsearch ignorecase smartcase hlsearch
0 2
%
Ctrl ^
^
5 :redo
10
scroll line ↓
T• ← until char Y
copy line
r
replace char
t•
copy
until char →
page ↓
file/cursor info
F• ← find char G
goto eof / goto line#
find char →
Normal / Cancel
block select
select lines select chars
X
← del char
C
change ⇥
V
x
del char →
c
change
0 2
v
g•
extra
6
page ↑
y
Ctrl 7
Ctrl 8
Ctrl 9
Ctrl 0
repeat :s
next identifier
begin sentence
end sentence
7
Replace
f•
&
soft ⇤
6 ctags return
0 2
*
I insert ⇤ O open ⤒ P
u
undo
i
paste ⤓
15
Join lines
K
h
←
j
↓
k
↑
N
b
↖ word
n
15
Ctrl M
Op Cmd Ins Move Find tag Code Extra • Modes n i v o c word
open ⤓
L
redraw Bottom screen
:
cmd line
l
→
;
"next" f/F/t/T
Ctrl ,
M
Middle screen
.
indent repeat cmd
Ctrl / 2
?•
find ↖
/•
find ↘
Ctrl =
autoformat
2
↑
{
Normal ↖ paragraph
}
paragraph ↘
[•
misc.
]•
misc.
=
ctags identifier
Ctrl '
16
↓
+
cur line
-
Ctrl ;
Ctrl . 2
_
0
o
Ctrl J
J
Ctrl _
↑
undo line
Top screen
↖ WORD
9
U
insert
:map :so $HOME/_vimrc
hard ⇤
paste ⤒
H
B
0 prev mark
man page identifier
↓ "prev" find find "next"
)
9
Ctrl I
Ctrl \ 0
"•
register
'•
goto mark ⇤
|
⇤
goto col#
\•
\
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
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 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 +123 :set filetype= goto line 123 :help range vim … -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 … -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 .,.+# 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 [] 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/^/\/\// block comment Macro
( 8
8 half page ↑
Ctrl H
9,16
Remove useless splash screen :set shortmess+=I
:map :e $HOME/_vimrc
R
half page ↓
A append ⇥
:suspend
$ 3
3
Q
Ctrl ^
Legend:
Ctrl 4
↰
Caps
Ctrl 3
1 14
Tab
Ctrl @
http:/michael.PeopleOfHonorOnly.com/vim/
May be freely distributed! Sharing is Caring.
Best scripts: http://www.vim.org/scripts/index.php
Ctrl 1
1
Copyleft © 2011
Vim Cheat Sheet for Programmers
↱
Esc
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 manually type §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/^\/\/// 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 → []
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