VI Editor Cheat Sheet / Survival Guide ;)

Let’s face it! The VI text editor (also know as VIM) can be quite intimidating. This VI cheat sheet shows the most commands to help even the newest VIM user survive. This is not the full list of VI commands, but these will help you whilst you are getting familiar with them.

Want a bit more detail? Why not view the how to use VIM guide.
Moving AroundCommand
Move the end of the fileG
Move leftLeft Arrow Key
Move rightRight Arrow Key
Move upUp Arrow Key
Move downDown Arrow Key
– You can also use: ‘j’ for down, ‘k’ for up, ‘h’ for left and ‘l’ for right.
General Save & Exit ControlsCommand
Save & Exit:x
Exit, No changes:q
Exit, Ignore changes:q!
– Both ‘:w’ and ‘:x’ requires you to have write permissions.
Insert Text & LinesCommand
Insert at the cursori
Insert before the lineI
Append text after the cursora
Append text after the lineA
Create a new lineo
– Each of these commands puts the vi into insert mode.
– Press the <Esc> key to put vi back into command mode.
– The ‘i’, ‘a’ and ‘o’ command supports undo if you press the * key.
Delete Text and LinesCommand
Delete the remainder of the line, from the cursorD
Delete the current linedd
– The command ‘dd’ supports undo if you press the * key.

VI Cheat Sheet Examples

Insert data into a new or existing file

When you run the command vim filename, an editor window will open.

Follow these steps to write data into a new or existing file.

  1. Press i to enter the insert mode
  2. Write any data you want to write to that file
  3. After you have written the data, press esc key to get out of the insert mode (to go back to normal mode)
  4. Press :w to save the changes without exiting from the editor window. Here, w means writing the changes to the disk
  5. Press :wq to both save the changes and exit from the editor. Here, w means you want to write changes to disk and q means you want to exit from the editor window.
  6. However, if you want to discard the changes you have made then press :q alone instead of :wq
  7. If :wq gives error then press :wq!

Copy and Paste data

To copy any line, press yy by taking the cursor to any position of any line.

To paste the already copied line, press p by first going to the normal mode(by pressing esc).

Moreover, you can also copy multiple lines by pressing Nyy Where N can be any number. For instance, to copy 5 lines we can press 5yy.

Search a string

To search any word from a file, first, open the file. Make sure you are in the normal mode (by pressing Esc). Now, press / followed by the search string e.g.


Moreover, if there are multiple occurrences of the search_string, then press n to go to the next occurrence. You can also go back to the previous occurrence by pressing shift+n.

Don’t like VI/VIM editor?

You could always install Nano text editor and save yourself the effort of learning vi editor.

To install Nano text editor on Debian or Ubuntu machines:

sudo apt-get install nano

To install the Nano text editor on CentOS or RHEL based platforms

sudo yum install nano
You may also want to read the official documentation at

About the Authors

Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic!

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee

Leave a Reply

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