Sometimes you need to edit a file with VI. Because the file is too big for other editors. Or you just have no other editor. But if you know these basic commands, using VI is really a pleasure:
Open, save, quit
| Command | Description |
| vi filename | open filename in VI |
| ZZ or :wq or :x | write changes to file and quit VI |
Switching between edit mode and command mode
| Command | Description |
| i | change to edit mode at cursor position |
| ESC | change to command mode |
Moving the cursor
| Command | Description |
| 1234G | move cursor to line 1234 |
| G | move cursor to end of file |
| 12| | move cursor to column 12 |
| /string | move cursor to first occurence of string |
| n | move cursor to next occurence of string |
Copy & paste, delete
| Command | Description |
| yy | copy current line into buffer |
| 3yy | copy next 3 lines into buffer |
| p | paste the line(s) in the buffer into the text after the current line |
| D | delete the remainder of the current line |
| dG | delete to end of file |
| dd | delete the current line |
| 3dd | delete the next three lines |
Search & replace
| Command | Description |
| s/string1/string2/ | replace all occurencies of string1 with string2 |