Basic vi commands

Martyn reckons you could use vi every day of your working life and never get to know all of the various key combination functions!

These are the 'quick start' commands Martyn uses in his training workshops:

Open, save, exit:
vi filename
- opens the file
:q - quit/exit
:q! - quit/exit, discard any changes
:x - quit/exit and save whatever you've done
:w - write changes, don't quit
:w [name] - writes as a new file with [name]

Editing:
i
- insert mode
esc - exit insert mode
dd - deletes the line you're working on
u - undo (can be repeated)
/word - find 'word'
/string of words - finds 'strings of words'
n - find next word or string of words
. - repeats the last command

Replace:
:s/this/that
- Replaces 'this' with 'that', first match in current line
:s/this/that/g - Replaces 'this' with 'that', all matches in current line
:%s/this/that/g - Replaces 'this' with 'that', all matches in current file (Global search and replace).

Cut, Copy, Paste:
v
- enter visual mode
Move the cursor to highlight the text
d - cut
y - copy
Move the cursor to target location
P - paste after cursor
p - paste before cursor