Vim
Operators and motions¶
- Every motion can be used after an operator command, so the command operates on the text comprised by the movement's reach.
- If the motion includes a count and the operator also had a count before it,the two counts are multiplied. For example:
2d3w
deletes six words. - Two repeated operators operate on the current line. For example:
g~~/guu/gUU
change case of all characters in a line
Operators¶
d
deletec
changey
yank into registerg~
swap casegu/U
make lowercase / uppercase- `` shift left / right
zf
define a fold
Word motions¶
w
next word (beginning)b
beginning of this word or previous worde
end of this word or next wordge
end of previous word
Left-right motions¶
0
To the first character of the line^
To the first non-blank character of the line$
To the end of the linef/F{char}
To the {count}'th occurrence of{char}
to the right / left.t/T{char}
Till before {count}'th occurrence of{char}
to the right / left of the cursor on the same line. The cursor is placed on the character left / right of{char}
;
Repeat latestf, t, F or T
{count} times,
Repeat latestf, t, F or T
in opposite direction {count} times
Up-down motions¶
{count}Enter/j/gj/+
{count} lines downward{count}Enter/k/gk/-
{count} lines upward
Text object motions¶
( / )
{count} sentences backward / forward{ / }
{count} paragraphs backward / forward[[ / ]]
{count} sections backward / forward- A sentence is defined as ending at a
. or ! or ?
followed by either the end of a line, or by a space or tab. - A paragraph begins after each empty line.
- A section begins after a form-feed (
<C-L>
) in the first column
Text object selection¶
a/iw
around / inner word[sd[sdas]a]a/is
around / inner sentencea/ip
around / inner paragrapha/it
around / inner tag, select {count} tag blocks, from the {count}'th unmatched<tag>
backwards to the matching</tag>
a/ib or ( / )
a / inner blocka/iB or { / }
a / inner {} blocka/i [/]//'/"/`
a / inner...
block
Jumps¶
*
To the next occurrence of the word under the cursor#
To the previous occurrence of the word under the cursor/{string}
To the next occurrence of{string}
?{string}
To the previous occurrence of{string}
n
Repeat latest search in same direction-
N
Repeat latest search in opposite direction -
:[range]
Set the cursor on the last line number in [range] gg/G
Go to line {count}, default first / last line, on the first non-blank character{count}%
Go to {count} percentage in the file, on the first non-blank in the lineH
top of screenM
middle of screenL
bottom of screen-
%
corresponding item -
g;
Go to {count} older position in change list g,
Go to {count} newer position in change list`{a-z/A-Z}
To the position of the specified mark'{a-z/A-Z}
To the first non-blank character in the line of the specified mark``/''
To the position before the latest jump
Other Operator¶
p
pastex
delete character, equal todl
o/O
insert line below / aboves/S
substitute character / line, equal tocl/cc
C
change character to end of lineu
undoU
restore the line to initial state<C-R>
redo
Other Commands¶
File¶
:e {relative path}
open or create a file:q
close window:w
save(write):wq
save and quit:q!
force quit and unsave:wq!
force quit and save
Fold¶
zo
open foldzc
close foldza
open / close foldzR
open all foldszM
close all foldszf
define a foldzd
delete a fold
Substitute¶
:{scope}s/{from}/{to}/{tag}
{scope}
: default is current line%
all lines in file10,20
from tenth line to twentieth line1,$
from first line to last line.,$
from current line to last line'a,'b
from line with mark a to line with mark b'<,'>
from the scope selected in visual mode
{tag}
: default is substiting the first matched stringg
globally in scopec
prompt for each substitutioni/I
case insensitive / sensitive
Mark¶
m{a-z/A-Z}
Set mark at cursor positiona-z
for in-file markA-Z
for global mark
Multiple Windows¶
:sp
split windows horizontally:vsp
split windows vertically
Macro¶
q{a-z}
record a macro into registerq
stop recording{count}@{a-z}
replay a macro {count} times# My Macro @l:insert list ### 0i-<Esc>j @s:insert list and space ### 0i- <Esc>j @p:chang list to pound, often used when paste commands from command-line manual ### 0r#jjdd
Navigation¶
gt/T
switch tab forward / backward{num}gt
switch to {num}'th tab{num}gT
switch num tabs backward<C-0>
Focus on Side Bar, andL
to open selected file<C-{num}>
Focus on {num}'th Group