Practical No:-4: Aim: - Familiarize With Vi' Editor and Linux Guis
Practical No:-4: Aim: - Familiarize With Vi' Editor and Linux Guis
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.
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