useful shortcuts

Vim Shortcuts (my list)

CTRL-O Move to previous cursor position

CTRL-I Move to next cursor position

ma Add a marker on current line with name "a"

'a Move to line marked "a"

Note: Mark with uppercase are global e.g. mA

di( Delete inside () - recursive

da( Delete inside () along with braces - recursive

dt; Delete till next ";'

df; Delete till next ";" along with ";"

dT; Delete till prev ";"

dF; Delete till prev ";" along with ";"

d3w Delete 3 words (w - start of word)

d3l Delete 3 characters (l - right arrow in vim)

d/<search_str> Delete till <search_str>. Works across lines


Note:

All the above movement commands works with "y" to yank (copy) or "c".

:h text-objects

:h fillchars

Vim shortcuts Ref: https://asic4u.wordpress.com/2016/06/23/handy-gvimvivim-commands/#more-1175

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)

0 (zero) start of line

i start insert mode at cursor

I insert at the beginning of the line

a append after the cursor

A append at the end of the line

o open (append) blank line below current line (no need to return)

O open blank line above current line

Esc exit insert mode

C delete from cursor position to end of the line

:E edit a file in a new buffer

:sp open a file in a new buffer and split window

Ctrl+ws split windows

Ctrl+ww switch cursor between windows

Ctrl+wq quit a window

Ctrl+w gf Edit existing file under cursor in new tabpage

Ctrl+w f Edit existing file under cursor in split window

gf Edit existing file under cursor in same window

Ctrl+wv split windows vertically

:%s/old/new/g replace all old with new throughout file

:%s/old/new/gc replace all old with new throughout file with confirmations

n repeat search in same direction

N repeat search in opposite direction

/pattern search for pattern

:w write (save) the file, but don’t exit

:wq write (save) and quit

:w! force write to a read only file

:q! force quit and throw away changes

yy yank (copy) a line

2yy yank 2 lines

dd delete (cut) a line

p put (paste) the clipboard after cursor

P put (paste) before cursor

dw delete (cut) the current word

yw yank word

~ switch case

Ctrl+v start visual block mode

u undo

. repeat last command

r replace a single character (does not use insert mode)

R replace characters till Esc is pressed

J join line below to the current one

:tabnew open new tab

:tabnew % open same file in new tab