0% found this document useful (0 votes)
50 views

Linux Vi Editor

Vi is a popular text-based editor used in Linux to edit configuration files and plain text documents. It has three modes - command mode to control cursor movement and editing commands, insert mode to add and edit text, and command-line mode to run commands. Vi is included in all Linux distributions and is useful when graphical editors are not available, though it has a cryptic interface compared to other editors.

Uploaded by

Ankur Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Linux Vi Editor

Vi is a popular text-based editor used in Linux to edit configuration files and plain text documents. It has three modes - command mode to control cursor movement and editing commands, insert mode to add and edit text, and command-line mode to run commands. Vi is included in all Linux distributions and is useful when graphical editors are not available, though it has a cryptic interface compared to other editors.

Uploaded by

Ankur Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

4.

Vi Editor
The Linux VI Editor is a text based editor used Linux, useful for editing
configuration files or creating plain text documents. Vi is one of the most
popular text editors texte under Unix type systems (with Emacs and pico).
Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi
(pronounced vee-eye) is an editor that is fully in text mode, which means
that all actions are carried out with the help of text commands. This editor,
although it may appear of little practical use at first, is very powerful and
can be very helpful in case the graphical interface malfunctions. Vi was
originally developed by William Joy at Berkeley University and first
officially included in AT&T System 5 Unix. It started out as a line-
oriented editor for dumb terminals. The Vi editor, or Vi improved (VIM)
is an enhancement by Bram Moolenaar it's the version that people use
today. The vi editor comes with every version of Linux or Unix. It's a
terribly unfriendly beast of an editor, but you should know about it
because someday you're likely to find yourself on a system where you
have no other choice but to use it
All Linux configuration files are written in plain English, easy to read and
to adapt. You use a text-editor to write or make changes to such files.
Using vi is similar to using other editors in that you can see your file on
the screen (this is not the case with a line editor, for example), move from
point to point in the file, and make changes. But that's where the
similarities end. Cryptic commands, a frustrating user interface, and the
absence of prompts can all drive you up a wall. The two most popular,
powerful, and unfortunately "difficult" text editors, both of which are
found in every Linux distro, are Vi and Emacs
To start Vi, open a terminal or console and simply type "vi" (without the
quotation marks) followed by the name of any existing file or a new file
you want to create. Vi works in two main modes, one for editing text and
the other for giving commands. To switch between the two modes you use
the I and Esc keys. The program opens in the Command mode, which is
used for cursor movements, delete, cut, copy, paste, and saving changes.
The hardest thing to understand about vi is the concept of modes. When
using vi, you're always in either Command or Input mode. The vi editor
has three modes, command mode, insert mode and command line mode.

1. Command mode: letters or sequence of letters interactively


command vi. Commands are case sensitive. The ESC key can end a
command.
2. Insert mode: we use it to make changes in an open file. Enter the
Insert mode by pressing the I key. Newer Vi versions will display
the word "INSERT' on the bottom line while you're in Insert mode.
Text is inserted. The ESC key ends insert mode and returns you to
command mode. One can enter insert mode with the "i" (insert), "a"
(insert after), "A" (insert at end of line), "o" (open new line after
current line) or "O" (Open line above current line) commands.
3. Command line mode: One enters this mode by typing ":" which
puts the command line entry at the foot of the screen.

Basic commands

Command Description

:q - Quit the editor (without saving)

:q! - Forces the editor to quit without saving (even if changes were
made to the document)

:wq - Saves the document and quits the editor

:filename - Saves the document under the specified name

Editing commands

Command Description

x - Deletes the character that is currently under cursor

dd - Deletes the line that is currently under cursor

dxd - Deletes x lines starting with the one currently under the cursor
nx - Deletes n characters starting with the one currently under the
cursor

x>> - Indents x lines to the right starting with the one currently under
the cursor

x<< - Indents x lines to the left starting with the one currently under
the cursor

Searching and Replacing

To search for a word in a document, in regular mode, just type / followed


by the chain of characters to be searched for and confirm by hitting the
Enter key. Use the n key to go from occurrence to occurrence.

To replace a chain of characters by another on a line, you will find a very


powerful command in Vi by using the regular expressions. Its syntax is as
follows:

:s/chain_to_be_replaced/replacement_chain/
IThe replacement can be made throughout the entire document with the
following syntax:
:%s/chain_to_be_replaced/replacement_chain/

You might also like