Learn the features that help you to edit, rather than write. You will spend much more time changing text than you spend writing it for the first time. vim is optimized for editing.
.
commandThe .
is vim's most basic power tool. It repeats the last
command that changed the file. Part of being effective in vim is learning how
to construct commands quickly that can be re-used with the .
.
A macro is a recorded set of vim commands that can be replayed at a later time. A map, on the other hand, is a way to define a new hot-key combination.
h
/j
/k
/l
b
/B
e
/E
w
/W
ge
/gE
0
/^
/$
f
/t
/F
/T ;
/,
H
/M
/L
zt
/zz
/zb
gg
G
{line}G
Ctrl-F
Ctrl-B
Ctrl-D
Ctrl-U
*
/#
[repeat]{command}{motion}
- apply command over range of motion[repeat]{command}{command}
- apply command to lines{repeat}{command}
- apply a command multiple timesd{motion}
/D
(D => d$)c{motion}
/C
(C => d$a)s{motion}
/S
(S => ^C)y{motion}
p{motion}
/P
m{a-zA-Z}
- set a mark`{mark}
- position of specified mark'{mark}
- beginning of line of specified mark``
- position of last edit''
- beginning of line of last edit{num}%
- percent of file:{line}
- Go to lineLowercase marks are in current buffer. Uppercase can reference other buffers.
w
W
s
p
]
/[
)
/(
/b
]
/[
/B
>
/<
t
"
'
`
caw
yiw
di"
gqap
gqat
:reg
"{reg}{command}
"{REG}{command}
"0
last yank"1
last delete or change"[2-9]
previous values of "1
""
"*
"+
"-
- within a line"_
"=
"%
"/
":
"add
- delete line into a
register"Add
- delete line and append to a
register"ap
- paste from a
register"_dd
- delete line without putting in registerCtrl-R
with expression register is handyvimdiff {files}
or vim -d {files}
do
/dp
to copy changesdiffget
and diffput
q{0-9a-zA-Z"}
begin recording a macroq
end macro recording@{0-9a-zA-Z".=*+}
execute specified macro@@
Execute last executed macro:s/re/replace/[g][c]
:g/re/{command}
:v/re/{command}
[range]y [x]
[line]pu [x]
[range]co {address}
[range]m {address}
[range]r [file]
[range]r !{cmd}
:ls
:{num}b
:n
/:N
:bd
:bufdo
:map
/:nmap
/:imap
etc.:nmap n nzz
:nmap N Nzz
Ctrl-W
is the window to the rest:sp [file]
/Ctrl-W s
- Split horizontally:vsp [file]
/Ctrl-W v
- split verticallyCtrl-W c
- close windowCtrl-W =
- make windows equal sizeCtrl-W +/-
- make windows larger/smallerCtrl-W h/j/k/l
- move to window in a directionCtrl-W w
- move to next windowvimtutor
- usually installed with vim:help {command}