Wonderful VIM

21 June 2016 Contribute to this post

Some useful VIM commands.

vim -N filename     Open in VIM mode (as opposed to default, the simpler VI mode)

CTRL + Z            Suspend VIM process (get back to shell)
fg                  .. resume VIM from shell
:sh                 Suspend VIM process (get back to shell)
exit                .. resume VIM from shell

i                   Insert mode
ESC                 Exit insert mode
dd                  Delete line
yy                  Copy line
P                   Paste before current line
p                   Paste after current line
r                   Replace character
x                   Delete character
u                   Undo
:q                  Quit
:q!                 Force quit
ZZ                  Save and quit
v                   Highlight character
V                   Highlight line
d                   Delete highlighted (and copy to clipboard)
y                   Copy highlighted

/searchterm         Search
n                   Go to next match
N                   Go to previous match

:%s/search/replace/gc   Search and replace (regex, so escape dots and so on)

.                   Repeat your last command
:e.                 To see and navigate files and folders, enter to edit file under the cursor
:e filename         Edit file within VIM
:! git status       To execute shell command 'git status'
:set number         See linenumbers
13G                 Go to line 13
cw                  Change word (cut, then activate insert mode)

:syntax enable      Enable syntax highligthing
:set syntax=html    Set syntax