Support / KnowledgeBase

 
Search the KnowledgeBase Search

Understanding basic vi (visual editor)

  • Applies to: All Service Types

  • Difficulty: Medium

  • Time needed: 10 minutes

  • Tools needed: None

 
  • Applies to: All Service Types
    • Difficulty: Medium
    • Time Needed: 10
    • Tools Required: None

Overview

vi (visual editor) is included with all (mt) Media Temple services. vi is a full screen editor and has two modes of operation.

  • Command Mode - every character entered is a command. This is the default mode when you start vi.
  • Insert Mode - this mode allows you to edit. To enter insert mode simply hit i once vi has started.

NOTE:

vi is case-sensitive. Be sure to not mix uppercase and lowercase letters when running commands, as the result will not be the same.

The best way to learn about vi is with the vimtutor, you can start your lesson by typing the following command via ssh:

vimtutor

Below is just a short list of a few commands that are very useful for beginners.

Instructions

Opening a file in vi

This first line is just to simply open a file with vi:

 
vi filename

The following command is used to recover a file that was being edited when the system crashed:


vi -r filename

The next command will open a file as read-only:


vi ew filename

To find a line in vi

You can use the following to go to the last line in the file:

G

To go the the first line of the file, you can use the following:


1G

To move around in the editor

  • type h to type move the cursor to the left
  • type l to move it to the right
  • type k to move up
  • type j to move down

To search within vi

To search for text in vi, you can use the "/" key followed by your search term. This example uses mttext:


/ mttext

To exit vi

To quit and not save changes, you can use:

:q!

If you want to quit and save changes, you can use the following command:

:x!

TIP:

The above examples only hint at the power of vi. It is very popular amongst developers/administrators for good reason. We strongly suggest making backups of any files before experimenting with vi, in case you need to revert your changes.


User Comments

No visitor comments posted. Post a comment
Fields marked with an asterisk(*) are required. Comment on this article
Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue