Introduction to Vim

Vim is a text editor - not a word processor. The difference being that a file created with a text editor contains no extra data to influence its visual presentation. For this reason, any file containing code to be executed by the operating system must be created using a text editor.

While there are many text editors, Vim is the most powerful in terms of functionality, and also the least reliant on system specifications. It is therefore regarded as the editor of choice for the Linux professional.

Start learning Vim

Before attempting the exercises in this chapter, learn the basics of Vim by running
vimtutor <ENTER>
and following the instructions. It will take between 25 and 30 minutes.

Subsequently, it may be helpful to keep this quick reference card open in a web page while you work.

Elementary Vim skills

The following are brief descriptions of some essential activities.

1. Starting Vim

From the command line you can start editing a file called "test.txt" (whether the file "test.txt" exists or not) with the command:
vim test.txt <ENTER>

2. Switching Modes

There are eleven types of mode when running Vim, but they can be categorised as two types: normal modes and insert modes.

Normal mode: When you start Vim you will be in normal mode, and at any time you can return to the normal mode by pressing the <ESC> key at the top left-hand side of your keyboard.

Insert mode: There are many ways to enter the insert mode, but the simplest is to type i. After typing i all the characters you type will be inserted into the docuement.

3. Exiting Vim

To exit Vim and return to the command-line:

  1. Go to normal mode by typing <ESC>
  2. Save and Exit: type :wq which stands for "write and quit".
  3. Exit without saving: typing :q! returns to the command-line without saving the changes you have made to the file.

References

  1. VimTutor, Michael C. Pierce and Robert K. Ware, Colorado School of Mines (using ideas supplied by Charles Smith, Colorado State University, modified for Vim by Bram Moolenaar.)
  2. Vim User Manual, Bram Moolenaar (last change: 24 April 2006).
  3. Vim Modes, Bram Moolenaar, Vim documentation for Vim version 7.0 (last change: 2 April 2006).
  4. Vim Quick Reference Card, Laurent Grégoire (last accessed: 20 May 2007).