You are on page 1of 1

Revision 1.

99

Normal

Vim 7.3+
:version

Sept. 9, 2011

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

Legend:
Macro

Op
Cmd
Ins
Move
Find
tag
Code
Extra

Modes
n
i
v
o
c
word

play
macro

prev
identifier

block select ^w window

ex mode

WORD

record
macro

word

incr. #

10

scroll line
end
WORD
end
word

subst line

del

subst char

del

7,11

decr. #

:suspend

quit

extra

4
5

0
2

Ctrl 4

Ctrl 5

goto
match

4
12

Ctrl ^

5
:redo

10

<CR> <NL> :set ff= dos unix mac

6
ctags return

scroll line

T until char Y

copy line

replace
char

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

del char

change

del char

change

0
2

extra

page

0
2

Ctrl 8

Ctrl 9

Ctrl 0

repeat :s

next
identifier

begin
sentence

end
sentence

(
8

8
half page

undo

paste

15

word

open

redraw
Bottom
screen

Ctrl J

Join lines

15

Ctrl M

Ctrl ,

Middle
screen

<

undent

set mark

"prev"
f/F/t/T

16

>
.

indent
repeat
cmd

Ctrl /
2

find

find

16

autoformat

Normal

paragraph

paragraph

misc.

misc.

ctags identifier

Ctrl '

Ex cmd line

"next"
f/F/t/T

Ctrl =

cur line

Ctrl ;

Ctrl .
2

Ctrl _

I insert O open P

undo line

insert

:map <F6> :so $HOME/_vimrc<CR>

hard

Top screen

WORD

0
prev mark

Ctrl I

man page
identifier

"prev"
find
find
"next"

paste

Ctrl H

9,16

Remove useless splash screen :set shortmess+=I

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

Ctrl 7

Replace

&

soft

half page

A append
append

$
3

Ctrl ^
Shift

extern filter

Caps

Ctrl 3

1
14

Tab

Ctrl @

Michael Pohoreski
michael@PeopleOfHonorOnly.com

May be freely distributed!


Sharing is Caring.

Search :set incsearch ignorecase smartcase hlsearch

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

Ctrl 1

Copyleft 2011

Vim Cheat Sheet for Programmers

Esc

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.

Register name (0-9a-zA-Z) required


Motion req.; act between cursor & dst
Command
a A s S c C R i I o O 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 ' " `

Ex cmd line
:w save
:q quit
:e <filename>
:source %
:exec '...'

: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
exec cmds in cur file ^p
complete word
:ta Foo manual jump to tag 'Foo'
do cmd

:help movement
Start of Line 1st non-whitespace
:help diff
:hi DiffAdd
guifg=#rrggbb
hard
[c prev diff
Start of Line column 0
:hi DiffChange guibg=#rrggbb
]c next diff
End of Line
:help modes
#| move col #
:diffupdate
:hi DiffText gui=none
move col 0
^f page
Esc ^[ ^c
Normal
page
resync :hi DiffDelete
^d page
a i r s
Insert
page
v V ^v ^q
Visual
scroll line ^y scroll line
:help changes
0g end of file
:changes
c d y < >
Op pending
start of file
:help folding
G end of file
zR fold remove
g; older change
Command Line : / ? !
goto line #
Foo ( src , dst , len );
zo fold open
g, newer change
begin this func {
zc fold close
Note: There is no whitespace in-between 'Foo(src,' but before/after 'dst,'
begin next func {
zi invert all
Foo ( src , dst , len );
WORD
:set matchpairs=(:),{:},[:],<:>,?:\:
% goto matching { } < > [ ]
zr fold reduce
Startup
:help recording
vim <filename> +123
zm fold more
q start recording
goto line 123
:help range
vim <file> -t Foo
:s/Foo/Bar
@ playback
edit at tag 'Foo'
find Foo replace w/ Bar
vim <file> -c "/Foo" cmd: find 'Foo' & edit :s/Foo/Bar/g ...all instances on line
q stop recording
GUI vim -g
gvim
:%s/Foo/Bar
@@ repeat
or
start GUI ver.
apply to whole file
:help syntax
.,.+# cur line, cur line + # lines
GUI Linux
:set guifont=ProggyTinyTT\ 12
:syntax enable
GUI OSX
:set guifont=ProggyTiny\:h11
$ last line
:set filetype=
c cpp sh make perl python
'< start of select '> end of select
diff gvimdiff <file1> <file2> [<file3>]
Note: means ONE OF
<< >>
>>
: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:$


0 See: src/ops.c -c "/valid_yank_reg" for " reg. names :set shiftwidth=# indent width for ai :set list!
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
soft

^
0
$
|
^b
^u
^e
1g
#g
[[
]]

\ :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
: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>]

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=
buffer last

You might also like