This is for when you get stuck with an abomination of an editor called vi. No sophisticated vi-foo here, this is just the basics that get you covered for simple editing of files.
The Vi editor has two modes: Command mode and Insert mode:
Some docs and tutorials refer to a third mode, the last line mode, which is for file operations like save and exit.
This mode can be entered from Command mode with
Got stuck in vi? Hit Esc to make sure in Command mode.
Now, in Command mode, to quit without saving, type , followed by return.
command mode is entered with the key
| i | input mode (insert before cursor) |
| a | input mode (insert after cursor) |
| x | delete char under cursor |
| <num>x | delete <num> chars from under cursor |
| dd | delete actual line |
| <num>dd | delete delete <num> of lines |
| u | undo last command |
| J | append next line to actual line |
| . | repeat last command |
| : | go into last line mode |
| :q! | quit without save |
| :w [<file>] | save as [<file>] |
| :x | save and quit |
| :e <file> | edit <file> |
| :u | undo last command |
| Key | Function |
|---|---|
| move one character to the left | |
| move one character to the right | |
| move one line up | |
| move one line down | |
| move one page up | |
| move one page down |
| Key | Function |
|---|---|
| h | move one character to the left |
| l | move one character to the right |
| k | move one line up |
| j | move one line down |
hit , then enter word to search for.
replace in line x to line y text1 with text2, without confirmation:
replace in line x to line y text1 with text2, with confirmation (note the at the end instead of ):