0% found this document useful (0 votes)
133 views3 pages

Practical No:-4: Aim: - Familiarize With Vi' Editor and Linux Guis

The document discusses the vi text editor in Linux. It describes vi as a full-screen text editor that allows users to view and edit entire documents. The document outlines vi's three modes of operation: command mode, insertion mode, and execution mode. It also explains how to invoke vi, navigate within files, perform editing operations like deleting and copying text, search for patterns, substitute text, and repeat commands. The document notes some disadvantages of vi such as lacking self-explanatory error messages and help functionality.

Uploaded by

Hitesh Gahlawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views3 pages

Practical No:-4: Aim: - Familiarize With Vi' Editor and Linux Guis

The document discusses the vi text editor in Linux. It describes vi as a full-screen text editor that allows users to view and edit entire documents. The document outlines vi's three modes of operation: command mode, insertion mode, and execution mode. It also explains how to invoke vi, navigate within files, perform editing operations like deleting and copying text, search for patterns, substitute text, and repeat commands. The document notes some disadvantages of vi such as lacking self-explanatory error messages and help functionality.

Uploaded by

Hitesh Gahlawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No:- 4

Aim: - Familiarize with ‘vi’ editor and Linux GUIs.

vi editor: - There are three types of editor

 ED
 EX
 VI

ED and EX are line editor, in this editor line number is assigned to the lines in a file where as vi
is the text editor or screen editor. The vi editor has been part of UNIX-based systems since the
1970s, and its interface shows it. It is arguably one of the last editors to actually use a separate
command mode and data entry mode; as a result, most newcomers find it unpleasant to use. The
vi editor is difficult to learn at first, but once you know it, you never have to use a mouse or a
function key—you can edit and move around quickly and efficiently within files just by using
the keyboard. It shows as much of the file as it can fit on screen. It is the first full screen editor
which allow the user to view and edit the entire document at a time creating and editing of a file
becomes easy using vi editor.

Starting vi or say to invoke vi


To create a file
Example: - $ vi file.txt
To invoke vi type vi and file name that you want to create when we type vi and the file
name press enter key then vi clears the screen and display a window in which we can enter and
edit text. The easiest way to learn more about vi is to start it and enter :help.

Mode of operations: - There are three mode of operation of vi editor.


 Command mode: - In this mode we insert text in blank text file or editing in existing
text file. Input mode also known as insertion mode. When a key is pressed of input mode
it does not appear on screen but subsequent key depressions do.
 Insertion mode: - In this mode all key passed by user are interpreted to the editor
commands that is for moving cursor for left-right top-bottom etc. In this the key pressed
are not displayed on screen. By default vi editor in command mode.
 Execute mode: - This mode is used to handle the files and perform substitutions. It
always starts with columns ‘:’.

Input mode: -
 Insert and append:-
i- To insert the text in a file to anywhere.
I- To insert the text in a file only at the beginning of a line.
a- To append the text in file any where
A- To append the text at end of line

Replace :-
r- Replace single terminal character in a file
s- One character replaced by multiple characters
R- Replace all text on the right of cursor position
S- Replace entire line
 Open line: -
o- Line editing at below of current line
O- Line editing at upper of current line
Execution mode: - These are following command.
:w- saves file and remains in editing mode
:x- saves file and quits editing mode
:wq- same as ‘:x’
:q- quit from editor without saving the buffer
:q!- forcefully quit from the editor without saving the buffer
:sh- escapes to UNIX shell
:recover- recovers file from a crash

Navigation: - There are several navigation keys for controlling the cursor movement. These
are as:
k- Moves cursor up
j- Moves cursor down
h- Moves cursor left
l- Moves cursor right
b- Moves back to beginning of word
e- Moves forward to end of word
w- Moves forward to beginning of word
0(zero) - moving to the beginning of a line
|- to position the cursor to certain column
$- moves to end of line
[Ctrl-f] - Scrolls forward
[Ctrl-b] - scrolls backward
[Ctrl-d] – scrolls half page forward
[Ctrl-u] - scrolls half page backward
G –goes to end of file

Editing text: - the editing facilities in vi are very elaborate and involve the use of operators.
There are two operators:
d- Delete
y- Yank (copy)
d and y are not commands, but they can be used for deleting and copying entire lines. These are
following commands for editing operations:
x- Deletes a single character under the cursor
dd- Delete the entire line
yy- Yank the entire line
p- Puts the data below the current line
P- Puts the data above the current line
j- Used to join the lines
u- To undo the last change made
U- Reverse all change made to the current line

Repeating the last command:- the vi editor has the facility to repeat the last command, but
most editor do not have. The dot (.) Command is used for repeating both Input and Command
mode that perform editing tasks.

Searching for a pattern: -vi is strong in search and replacement activities. Searching can be
made in both forward and reverse directions, and can be repeated. It is initiated from the
Command mode by pressing a /, which shows up in last line as :
/ - For forward search
? - For backward search
Command for repeating the last pattern searches are:
n- Repeats search in the same direction along which previous search was made
N- Repeats search in direction opposite to that along which previous search was made

Substitution: - vi offers yet another powerful feature, that of substation, which is achieved
with the ex mode‘s’ command. The syntax is as:
:address/source_pattern/target_pattern/flags
The source_pattern is replaced with target_pattern in all lines specified by address. The address
can be one or a pair of numbers, separated by a comma. The most commonly used flag is g,
which substitute all occurrences of the pattern in a line. For example:
:1,$s/director/member/g
The target pattern is optional. If you leave it out, then you’ll delete all occurrences of the source
pattern in all lines matched by address. For example:
:1,23s/member//g

Interactive substitution:- something like to selectively replace a string. In this case, add the ‘c’
(confirmatory) parameter as the flag at the end:
:1,$s/director/member/gc

Disadvantages: -
 There are no of self explanatory error message in vi if anything goes wrong then there is
an error message appear. Only speaker keeps to inform that something wrong
 No help available in vi editor
 There are three mode in which vi editor work but in each mode same key create different
effects
 vi is key sensitive. Vi can handle that maintain plain text that no fstyle in fault. No
graphic just simple text file we can create, edit and print

You might also like