Getting Started
Vim Action = Operator + Motion
Operators
Trigger | Effect |
---|---|
c | Change |
d | Delete |
y | Yank |
g~ | Switch case |
gu | Lowercase |
gU | Uppercase |
> | Shift right |
< | Shift left |
= | Autoindent |
Custom Operator
Trigger | Effect | Plugin |
---|---|---|
z | to the next search result | vim-sneak |
s | to surround text object with quotes, brackets or HTML tags | vim-srround |
Motions
Left-Right Motions
Trigger | Effect | ||
---|---|---|---|
h | characters to the left | ||
l | characters to the left | ||
0 | to 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
Trigger | Effect |
---|---|
j | line downward linewise |
k | line upward linewise |
gg | goto line [count], default first line |
G | goto line [count], default last line |
Word-Motions
Trigger | Effect |
---|---|
w | jump by start of words (punctuation considered words) |
W | jump by words (spaces separate words) |
e | jump to end of words (punctuation considered words) |
E | jump to end of words (no punctuation) |
b | jump to start of words (punctuation considered words) |
B | jump to start of words (no punctuation) |
Text Object Motions
Trigger | Effect |
---|---|
( | sentences backward |
) | sentences forward |
{ | paragraphs backward |
} | paragraphs forward |
Text Object Selection
Modifiers | Effect |
---|---|
a | a ..., leading or trailing white space is included, but not counted. |
i | inner ..., white space between words is counted too. |
Object | Effect |
---|---|
w W | word |
s | sentence |
p | paragraph |
[ ] | bracket block |
{ } | brace block |
( ) | parenthesis block |
< > | angle bracket block |
t | html 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
Keystrokes | Effect |
---|---|
C-h | delete back one character |
C-w | delete back one word |
C-u | delete back one line |
Go back to Normal Mode in Insert Mode
Keystrokes | Effecct |
---|---|
Esc | switch to normal mode |
C-[ | switch to normal mode |
C-o | switch 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.