Practical Vim Tips

5 min read
banner image

Getting Started

Vim Action = Operator + Motion


g~Switch case
>Shift right
<Shift left

Custom Operator

zto the next search resultvim-sneak
sto surround text object with quotes, brackets or HTML tagsvim-srround


Left-Right Motions

hcharacters to the left
lcharacters to the left
0to the first character of the line
^to the first non-blank character of the line
$to the end of the line
f{char}to the first occurrence of {char} to the right
F{char}to the first occurrence of {char} to the left
t{char}till before the first occurrence of {char} to the right
T{char}till before the first occurrence of {char} to the left

Up-Down Motions

jline downward linewise
kline upward linewise
gggoto line [count], default first line
Ggoto line [count], default last line


wjump by start of words (punctuation considered words)
Wjump by words (spaces separate words)
ejump to end of words (punctuation considered words)
Ejump to end of words (no punctuation)
bjump to start of words (punctuation considered words)
Bjump to start of words (no punctuation)

Text Object Motions

(sentences backward
)sentences forward
{paragraphs backward
}paragraphs forward

Text Object Selection

aa ..., leading or trailing white space is included, but not counted.
iinner ..., white space between words is counted too.
w Wword
[ ]bracket block
{ }brace block
( )parenthesis block
< >angle bracket block
thtml tag block
" 'quote block

Vim Tips

Number Increment and Decrement

Pressing C-a or C-x to increse or decrease a number by 1. If the current cursor is not a number, it will find the first number of the current line.

Multiline Operation

Press C-v to enter Visual-Block mode, then select target lines, then do operation on one line. For insert, use I to enter insert mode.

Make Correction in Insert Mode

C-hdelete back one character
C-wdelete back one word
C-udelete back one line

Go back to Normal Mode in Insert Mode

Escswitch to normal mode
C-[switch to normal mode
C-oswitch to insert-normal mode

In insert-normal mode, we can excute a single command then switch to insert mode immediately.

Paste from a Register without Leaving Insert Mode

Pressing C-r {register} in insert mode.

Pressing C-r C-p {register} to insert text literally and fix any unintended indentation.

Evaluate an Expression from Register

Pressing C-r={expression} to evaluate an expression and paste it directly without leaving insert mode.

Insert Character From ASCII Code or Unicode

From insert mode, type C-v{code} with a three-digit number to insert a character.

For example, A can be inserted with C-v065.

Unicode characters can be inserted using a four-digit hexademical code.

For example, ¿ can be inserted with C-vu00bf.

Besides, we can insert character literal by using C-v{char}.

For example, we can insert a tab with C-v<Tab>.

Insert Digraph in Insert Mode

æ can be inserted using C-vae, and ¿ can be inserted using C-v?I.

Overwriting Text with Replace Mode

Press R to enter replace mode, then the following typed characters will overwrite existing text.

A tab character is visually of multi-character length, but it represents a single character. And replace mode treats a tab as s single character.

In virtual replace mode, triggered by pressing gR, a tab chracter is treated as multuple characters as in tabstop setting.

Use r{char} or gr{char} to apply a single replacement.

Selecting with Visual Mode

There're three visual mode variants, character-wise, line-wise and block-wise visual mode, triggered by v V C-v respectively.

In visual mode, one end of the selected text is fixed, and the other moves freely with our cursor. We can use o to go to the other end of selected text.

Press gv to reselected the last visual selection.