VIM : SOME KEYBOARD SHORTCUTS

BASICS COMMANDS

iINSERT mode at the cursor position
aINSERT mode at the right of cursor
AINSERT mode at the end of the line
:qEXIT Vim
:q!EXIT Vim without save
:wSAVE the file current
:w <file>SAVE the file current as <file>
:wqSAVE and EXIT
:xSAVE (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

THE MODES

vVISUAL, select the text character by character
CTRL + vV-BLOCK, select text on the witdh of the column
SHIFT + vV-LINES, select text line by line
SHIFT + rREPLACE, replace each letter with the one entered

MOVE

hMove the cursor one character to the left
jMove the cursor at the bottom line
kMove the cursor at the top line
lMove the cursor one character to the right
ggMove the cursor at the beginning of the first line of the document
GMove the cursor at the beginning of the last line of the document
G<number line>Move the cursor to the line number
0Move the cursor to the beginning of the line
$Move the cursor to the end of the line
eMove the cursor to the end of next word
nwMove the cursor of n word(s) forward
neMove the cursor to end of nth word forward

EDIT COMMANDS

uCancel the last action
Ctrl + rRestore canceled action
.Repeats the last editing action
UCancel all changes on a line
yyCopy a line (4yy = 4 lines)
ddCut a line (4dd = 4 lines)
pInsert after (P = insert before) the curso, to the next line
xErase character
ceErase from the cusor and until the end of the word, and go into INSERT mode
CClears to the end of line
ddErase the current line
deClears until the end of the current word
dwClears until the beginning of the next word
d$Clears until the end of the line
diwClears the word under the cursor

COPY /PASTE

y  → Copy
p  → Paste

SEARCH / REPLACE

/Search down the document
?search up the document
%Type % to find matching ), ], or }, after placing the cursor on one of the occurrences in question
nFind the next occurrence
NFind the previous occurence
.Repeat the last action
:s/OLD/NEWReplace the next OLD by NEW, on the line
:s/OLD/NEW/gReplace all (g) OLD with NEW, on the line
:%s/OLD/NEW/gReplaces all occurrences of the entire file
:%s/OLD/NEW/gcFind all occurrences in the entire file with a prompt to confirm or deny each substitution
:#,#s/OLD/NEW/gFind 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>

SPLIT

CTRL+w et sHorizontal division
CTRL+w et vVertical division
CTRL+w et =equalize the size of the viewport
CTRL+w et wSwitch viewport
CTRL+W et CTRL+<direction>Move to the viewport in the desired direction with H, J, K et L
CTRL+w et nOpen a blank file in a new window
CTRL+w et rChange the viewports
CTRL+w et RChange the viewports, reverse
CTRL+w et qClose the split

TABS

:tabnew fileOpen file in tab
:tabnextGo to the next tab (gt)
:tabpreviousGo to the previous tab (gT)
:tabcloseClose tab

ACTIVATE / DEACTIVATE OPTION

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

OPEN/SAVE/EXIT/CHANGE FILE (buffer)

:e <path/to/file>Open file
:wSave
:saveas <path/to/file>Save as …
:x, ZZ ou :wqSave and exit (:x backup only if necessary)
:q!Exit without save. Likewise :qa! exits even if other files (buffers) have unsaved changes
:bnShow the following file
:bpShow the file previous

REPETITION IN POWER

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 ;)

Typing a number before a move repeats it as many times
Typing a number with an operator repeats it as many times