i | INSERT mode at the cursor position |
a | INSERT mode at the right of cursor |
A | INSERT mode at the end of the line |
:q | EXIT Vim |
:q! | EXIT Vim without save |
:w | SAVE the file current |
:w <file> | SAVE the file current as <file> |
:wq | SAVE and EXIT |
:x | SAVE (only if changing) and EXIT |
:!<command> | Execute a Shell command |
:r !<command> | Get the result of the command and insert it under the cursor position |
:r <file> | Get the content of <file> and insertit under the cursor position |
v | VISUAL, select the text character by character |
CTRL + v | V-BLOCK, select text on the witdh of the column |
SHIFT + v | V-LINES, select text line by line |
SHIFT + r | REPLACE, replace each letter with the one entered |
h | Move the cursor one character to the left |
j | Move the cursor at the bottom line |
k | Move the cursor at the top line |
l | Move the cursor one character to the right |
gg | Move the cursor at the beginning of the first line of the document |
G | Move the cursor at the beginning of the last line of the document |
G<number line> | Move the cursor to the line number |
0 | Move the cursor to the beginning of the line |
$ | Move the cursor to the end of the line |
e | Move the cursor to the end of next word |
nw | Move the cursor of n word(s) forward |
ne | Move the cursor to end of nth word forward |
u | Cancel the last action |
Ctrl + r | Restore canceled action |
. | Repeats the last editing action |
U | Cancel all changes on a line |
yy | Copy a line (4yy = 4 lines) |
dd | Cut a line (4dd = 4 lines) |
p | Insert after (P = insert before) the curso, to the next line |
x | Erase character |
ce | Erase from the cusor and until the end of the word, and go into INSERT mode |
C | Clears to the end of line |
dd | Erase the current line |
de | Clears until the end of the current word |
dw | Clears until the beginning of the next word |
d$ | Clears until the end of the line |
diw | Clears the word under the cursor |
y → Copy
p → Paste
/ | Search down the document |
? | search up the document |
% | Type % to find matching ), ], or }, after placing the cursor on one of the occurrences in question |
n | Find the next occurrence |
N | Find the previous occurence |
. | Repeat the last action |
:s/OLD/NEW | Replace the next OLD by NEW, on the line |
:s/OLD/NEW/g | Replace all (g) OLD with NEW, on the line |
:%s/OLD/NEW/g | Replaces all occurrences of the entire file |
:%s/OLD/NEW/gc | Find all occurrences in the entire file with a prompt to confirm or deny each substitution |
:#,#s/OLD/NEW/g | Find where #, # are the line numbers of the range where the substitution is to be made |
**EXAMPLES**
If you want to ignore case only for a search, use \c at the end of the search pattern : /test\c <Enter>
CTRL+w et s | Horizontal division |
CTRL+w et v | Vertical division |
CTRL+w et = | equalize the size of the viewport |
CTRL+w et w | Switch viewport |
CTRL+W et CTRL+<direction> | Move to the viewport in the desired direction with H, J, K et L |
CTRL+w et n | Open a blank file in a new window |
CTRL+w et r | Change the viewports |
CTRL+w et R | Change the viewports, reverse |
CTRL+w et q | Close the split |
:tabnew file | Open file in tab |
:tabnext | Go to the next tab (gt) |
:tabprevious | Go to the previous tab (gT) |
:tabclose | Close tab |
Typing ":set xxx" activates the option "xxx".
Some options are :
→ 'ic' 'ingnorecase' to ignore the case during searches
→ 'is' 'incsearch' to show partial matches
→ 'hls' 'hlsearch' to highlight pairings
:e <path/to/file> | Open file |
:w | Save |
:saveas <path/to/file> | Save as … |
:x, ZZ ou :wq | Save and exit (:x backup only if necessary) |
:q! | Exit without save. Likewise :qa! exits even if other files (buffers) have unsaved changes |
:bn | Show the following file |
:bp | Show the file previous |
1) In COMMAND mode, enter the number of times for the repeat
2) i
3) Enter text
4) Press Esc as many times as needed
5) In COMMAND mode again, enter a new number of times to repeat
6) To push on . as many times as necessary ;)