vi is a powerful built-in Linux command line text editor. The name vi is from visual editor.
It does not have menus, it has a lot of shortcuts and it is not similar to Notepad or TextPad, etc.
It may look strange at first but it is a very powerful tool that you may end up using everyday on your Linux.
The vi editor has two modes: Command and Insert.
You can think of the Command mode as your (invisible) menu and “tools” window and the Insert mode is your editing mode where you insert/replace text.
When you first open or create a file with vi, you are in Command mode.
To go to Insert mode, press i, to return to Command mode, press Esc.
The most basic commands that you need to know are:
Command | Description |
i | Switch from Command mode to Insert mode |
Esc | Switch from Insert mode to Command mode |
:w | Write (Save) the file |
:w filename | Similar to what we call today “Save As…” (except the next write will still be to the original filename) |
:q | Quit vi (when the file is saved) |
:q! | Quit even if the file is not saved |
:wq | Save and quit |
:sh | Execute shell commands (return with <ctrl> + d) |
Right-Click | In Insert mode, it will paste the clipboard’s content. this is probably the coolest thing in vi today |
/string | Search forward |
?string | Search backward |
To use vi to edit configuration files, short bash scripts, etc., the above commands should be enough.
There are lots of other shortcuts that you mind find useful at some point but to keep this simple I will not add more.
If you want to learn some more commands, here is a “cheat sheet”: