Cambridge IT Courses logo

Cambridge IT Courses: Specialists in advanced IT training

Cambridge IT Courses Blog: 5 commands you need to know to use VI

VI: THE command line editor

The VI editor has powerful features to aid programmers and as it runs on the command line it makes it particularly useful if you need to edit files on a server. However, many beginning users avoid using VI because of the steep learning curve. That's why we'll show you 5 commands you need to know to use VI:

You open a file with:


If the file doesnt exist, it will be created!

VI Modes

In Vi you have to switch between three basic modes:
  • Command Mode
  • Insert Mode
  • Line Mode

Switching modes:

The Command mode is the normal mode you are in when you enter the VI.
When you are in Insert mode you can enter Command mode by pressing "Esc".

Insert mode is the mode you use when you want top write or change text.
You can enter Insert mode by pressing "Esc" for Command mode and then lowercase "a" followed by "Enter".
Now you can write or change code.

The Line mode is used for Line oriented commands, such as searching for strings in your code.

5 useful VI commands:

Saving files:

Go into Command mode (press "Esc" if in doubt), then type:
Followed by "Enter".

Closing VI:


To save and exit use:

VI Viewing options:

:vsplit and :hsplit 
you can split the VI horizontal or vertical. With that function you can easily compare code or work on you HTML and CSS sheet at the same time

For line numbers you can use
to show them, or
to hide them!

Copy and Delete:

When you want to paste or copy code you can use
:y for 1 line or :y3 for 3lines

When you want to delete one or more lines use:
:d or :d3 for 3lines

Once you've mastered the basics get yourself a good 'cheat sheet' such as: And when you've used VI for a while writing code with shortcut commands will be much more efficient than a GUI/ mouse based text editor!
Posted by Deniz Gruenberger at 22:15 2011-05-21 | Trackbacks (0) | Comments (0)
Cambridge IT Courses Blog

Articles, tips and tricks discussing technical issues related to our courses

Blog Posts