Vi is what is known as a modal editor - that means it has a number of modes in which it operates.
When you first start vi it is in command mode. Some common command mode key sequences:
- :q - Quit
- :q! - Force quit
- :w - Write file
- :wq! - Forced write file and exit
- :w /path/to/my/new/file - Write to a new file
- :r /path/to/file - read file and insert into buffer
To switch into one of the editing modes:
- i - Enter insert mode infront of the current character
- r - Replace single character
- R - Enter replace mode
- a - Enter insert mode after the current character
- A - Enter insert mode at the end of the current line
- o - Open a new line below cursor and enter insert mode
- O - Open a new line above cursor and enter insert mode
To return to command mode just press Esc
There are a huge number of other keypresses in command mode - this list is pretty useful.