Basic Vim Usage

Sample Image

Mode

Vim have 2 mode , Command mode and Insert mode
Esc (Commmand Mode)
i (Insert Mode)

Global

:help keyword (open help for keyword)
:o (openfile)
:saveas file (save file as)
:close (close current pane)

Cursor Movement

h( move cursor to left)
l (move cursor to right)
j (move cursor to down)
k (move cursor to up)
e (jump forwards to the end of a word)
w (jump forwards to the start of a word)
H(move to top of screen)
M (move to the middle of the screen)
L (move to the end of the screen)
b (jump backwards to the start of a word)
gg (go to the first line of the document)
G (go to the last line of the document)
5G (go to line 5)

Exiting

:w (save the file , but don't exit)
:w !sudo tee % (write out the current file using sudo)
:wq or :w or ZZ (save and quit)
:q (quit)
:q! and ZQ (quit and throw away unsaved changes)
:wqa (save and quit on all tabs)

Insert Mode

i - (insert before cursor)
I - (insert at beginning of the line)
a - (append after cursor)
A - (append at the end of line)
o - (open a new line below the current line)
O - (append a new line above current line)
ea - (insert at the end of the word)
Esc - (exit inset mode , change to the command mode)

Editing

r - ( replace a single character)
J - (join line below the current one with one space in between)
gJ - (join line below the current one without space in between)
cc - ( change entire line)
C - (change to the end of the line)
s - (delect character and substitue text)
S - (delect line and substitute text (like cc )
u - (undo)
Ctrl +r - (redo)
. - (repeat last command)

Visual Mode

Ctrl+v - (start visual block mode)
v - (start visual mode)
V - (start linewise visual mode)
o - (move other end of marked area)
O - (move other corner of block)
aw - (mark a word)
Esc - (exit visual mode)

Visual Commands

> - (shift text right)
< - (shift text left)
y - yank (copy maked text)
d - (delete marked text)
~ - (switch case)

Cut and Paste

yy - (copy a line)
2yy - (copy 2 line)
yw - (copy the characters of the word from the cursor position to the start of the next word)
y and Shift+4 - (copy to end of line)
p - (paste clipboard after cursor)
P - (paste befor cursor)
dd - (delect a line)
2dd - (delect 2 lines)
dw - ( delect the characters of the word from the cursor position to the start of the next word)
D - ( delect to the end of the line)
d$ - (delect to the end of the line)
d0 - (delect to the beginning of the line)
x - ( delect character)

/pattern - (search for pattern)
?pattern - (search backward for pattern)
n - (repeat search in same direction)
N - (repeat search in opposite direction)
:%s/old/new - (replace all old with new )
:%s/old/new/c - (replace all old with new with confirmtion)
:noh - (remove highlighting of search matches)

:vimgrep /pattern/ {file} - (serach for pattern in multiple files)
:cn - (jumps to the next match)
:cp - ( jump to the previous match)
:copen - (open window containing the list of matches)

Working with Multiple Files

:e file - (Edit file in a new buffer)
:bd - (close a file)
:ls - (list all open buffer)
:sp - (open file in a new buffer and split window)
:vsp - (open a file in a new buffer and vertically split window)
Ctrl + ws - (split window)
Ctrl + ww - (switch windows)
Ctrl + wq - (quit a window)
Ctrl + wv - (split window vertically)
Ctrl + wh - (move cursor to the left window vertical split)
Ctrl + wl - (move cursor to the right window vertical split)
Ctrl + wj - (move cursor to the window below horizontal split)
Ctrl + wk - (move cursor to the window above (horizontal split)

Extra

:X - ( Save with encryption key(password) )