|
Page 1 of 3 vim Editor Tutorial
Emacs may show its age, but
before there was an emacs, vi was the best thing around. The fact
that vi is still here, and still being used, shows that it, like
shells and shell scripts, still serves a purpose for many users.
Vi, short for visual editor, is a modal editor. In vi, there are
two modes: insert and command. In insert mode, the text you type
gets entered into the file you are editing. In command mode, the
keys you type are interpreted as vi commands, short cryptic
commands that can have a major effect on your
To start vi, simply enter the vi command:
$ vi
You can also start vi with a session editing a particular file. For
example:
$ vi script1
This command tells vi to edit a file named script1 in the current
directory. Vi can create the file if it does not
exist.
You can pass more than one file name on the command line. For
example:
$ vi script1 script2 script3
Vi shows each file one at a time. The :n command (see the second
table following) jumps to the next file.
When you start vi, the editor places you in command mode. Thus, any
keys you start typing are assumed to be commands. Unlike emacs, you
cannot just start typing text. Instead, you have to enter a command
to switch to insert mode. The most common command to enter insert
mode is a lowercase i, short for insert.
The following table lists the commands to switch over to insert
mode.
Vi Insert Command Purpose
i Inserts before the current character
I Inserts at the beginning of the line
a Appends after (to the right of) the current
character
A Appends at the end of the current line
o Inserts a new line after the current line
O Inserts a new line before the current line
Once in insert mode, the text you type gets entered into the file
you are editing. Press Esc to exit insert mode.
Some versions of vi display text at the bottom of the editor
telling you that you are in insert mode, such as the
following:
-- INSERT --
But many versions of vi provide no feedback as to which mode you
are in. If you&rsquore ever unsure, just press Esc twice. If
you are already in command mode, vi merely beeps at you. When you
get into command mode, vi beeps at you.
One of the best descriptions of vi is that it is a program that
beeps at you a lot.
|