Intro to Linux vi Editor

Categories:

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:

CommandDescription
iSwitch from Command mode to Insert mode
EscSwitch from Insert mode to Command mode
:wWrite (Save) the file
:w filenameSimilar to what we call today “Save As…” (except the next write will still be to the original filename)
:qQuit vi (when the file is saved)
:q!Quit even if the file is not saved
:wqSave and quit
:shExecute 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
/stringSearch forward
?stringSearch 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”:

Leave a Reply

Your email address will not be published. Required fields are marked *