Shortcuts
:help help
:q quit
:w write
:o open
esc escape mode
i insert mode
c - change mode
v - visual mode to select chars
V - visual line mode to select lines
vim tutor to learn
hjkl - left, down, up, right
u - undo
w - next start of word
b - last start of word
e - next end of word
f - find
x - delete char
dd - delete line
yy - copy line
yw - copy word
p - paste at cursor
P - paste before cursor
ctrl + r, 0 - paste in insert mode
r - replace with
3l - 3 times l key
di( - delete inside next (
da( - delete around next (
. - repeat last action
gg - go to start of file
G - go to end of file
dw: delete next (word)
ddp: swap lines
:% s/foo/bar/g: in all lines (`%`), `s`ubstitute (= search & replace) `foo` with `bar`
:% s/foo/bar/gc: in all lines (`%`), `s`ubstitute (= search & replace) `foo` with `bar`, ask for `c`onfirmation on each occurency
:1,$ s/foo/bar/g: from line `1` to the end (`$`), `s`ubstitute (= search & replace) `foo` with `bar`
:.,$ s/foo/bar/g: from the current line to the end (`$`), `s`ubstitute (= search & replace) `foo` with `bar`
:s/foo/bar/g: in the current line, `s`ubstitute (= search & replace) `foo` with `bar`
Advanced
- add text to multiple lines:
- highlight multiple lines with Shift+V
- type `:`: you will see `:'<,'>`
- type `norm A`: this goes into `norm`al mode and `A`ppends to the end of the line
- type whatever you want to add
- example: `:'<,'>norm A;`: adds a `;` to the end
- you can do the same for the start of a line by using replacing `A` with `I`
- delete inside next parentheses:
- find next opening parentheses: `f(` (hit `;` for the next location)
- delete inside parentheses: `di(`
Links
- https://vimawesome.com/
- https://vim-adventures.com/
- http://www.vimgolf.com/
- https://vim.fandom.com/wiki/Search_and_replace