Beruflich Dokumente
Kultur Dokumente
vi modes
vi has two different modes. One is Command Mode, the other is Text Entry Mode:
Command Mode
In Command Mode everything that you type is interpreted as a command. For
most commands, a single keystroke is the entire command, while other
commands require more information, such as a linecount followed by a singlecharacter command. Command mode is used to perform powerful editing
functions, as well as such actions as writing the text buffer to a file. To enter
Command Mode from Text Entry mode, type an <ESC> character.
Text Entry Mode
In Text Entry mode all characters typed are printed on the screen and become
part of the current document. Editing in this mode is restricted to insertion and
typeover. To enter Text Entry Mode from Command Mode, type the character 'i'
(for insert mode), 'a' (for append mode), or 'o' (for open mode).
Description
vi is actaully the command which starts the visual mode
of ex, the landmark editing program developed by Joy. As
ex gained popularity, Joy noticed that most users were
exclusively using its visual mode, so to make things more
convenient for his users, he added a link to ex which
started it in visual mode automatically. Today vi is the
most popular text editor among Linux users.
A more feature-rich implementation of vi named vim
(which stands for "vi improved") is also available.
Options
Using vi
vi is an interactive text editor which is display-oriented:
the screen of your terminal acts as a window into the file
you are editing. Changes you make to the file are
reflected in what you see.
Using vi you can insert text anywhere in the file very
easily. Most of the vi commands move the cursor around
in the file. You can move the cursor forward and
backward in units of characters, words, sentences, and
paragraphs. Some of the operators, like d for delete and
c for change, can be combined with the motion
Editing A File
Arrow Keys
The syntax for replacing one string with another string in the current line is
:s/pattern/replace/
Here "pattern" represents the old string and "replace" represents the new string. For
example, to replace each occurrence of the word "lemon" in a line with "orange," type:
:s/lemon/orange/
The syntax for replacing every occurrence of a string in the entire text is similar. The
only difference is the addition of a "%" in front of the "s":
:%s/pattern/replace/
Thus repeating the previous example for the entire text instead of just for a single line
would be:
:%s/lemon/orange/
You can also append text from the currently open file to any other file. This is accomplished
using the :w (colon + "w") command followed without a space by >>. For example, to
append the contents of a currently open file named "pear" to the file named "apple," type
:w>> apple
At times it can be convenient to open multiple files simultaneously. This is efficiently
accomplished by just listing all of the files to be opened after the vi command. For
example, to simultaneously open files about three kinds of fruit, type:
vi apple pear orange
This allows you to edit "apple" first. After saving "apple," typing :n calls up "pear" for
editing.
If you want to simultaneously open all files in the current directory, just type vi * (vi +
space + asterisk).
Inserting
r
replace character under cursor with next
character typed
R
i
O
mode
Deleting
x
dd
dw
db