Old Content This page is now considerably out-of-date.
Vi is a text editor often found on Unix systems. I don't particularly like it, and generally avoid using it, but it has the benefit of being almost always available.
The difference between vi and most other editors is it has two modes: command mode and insert mode. You start off in command mode, and usually press i to get into insert mode, where you can actually type. To get back to command mode, press escape. In some versions of vi it tells you at the bottom if you're in insert mode, otherwise you have to remember.
There's not much to say about insert mode - you just type. Here are the most common keystrokes I use in command mode:
|forward a word
|back a word
|end of line
|beginning of line
|end of file
|go to line num
|beginning of file
|alternative cursor keys (left, down, up, right)
Cut & paste
|cut the current line
|copy the current line
|delete a word
|cut from cursor until end of line
|paste after cursor
|paste before cursor
Getting into insert mode
|insert text before cursor
|append text after cursor
|append text at end of line
|change a word
|change from cursor to end of line
|substitute character at cursor
|repeats last operation. very good with 'dd'
|do cmd repeated num times
|replace a character without going into insert mode
|save and quit
|runs a shell command
Points to note
- If it all goes totally mad, you've probably got caps-lock on by mistake.
- You can get out of the help with :q
- Sometimes you paste into vi (in a x-term or putty window) and it misses part of the text. That's when you've done it in command mode - it starts doing your text as commands (which can wreak havoc) and drops into insert mode when it his an i, finally typing some of what you pasted.