vi editor
It is also called visual editor.
To start , in the Unix prompt type vi filename and press enter, the file name could be new or
existing.
If new file name is given, new file will be created. If
existing file name is given , it opens the existing file which you can edit .
As soon as , you enter vi filename and press ENTER , you
will see vi editor window in command mode . You can press "i" to
switch to insert mode . In insert mode you can edit the file.
After you edit the
file, you can save it, save and exit or exit without save. To do this, you need
to switch to command mode. you can press "Esc" to switch to command
mode from insert mode.
In command mode,
":w" press ENTER --- to save the file
":q!" press ENTER --- to quit vi editor without
saving the file
":wq" press ENTER --- to save the file and quit vi
editor
Vi Editor has two modes of operations :
command mode
--- move the cursor, copy/paste,delete, undo, find total lines, line number,
search string, sroll page, save. As soon as the vi editor opens, it is in command
mode. To switch to insert mode , press "i"
insert mode
--- in this mode you can insert , delete
, replace text to the file. To switch to command mode , press
"Esc".
Vi editor is case sensitive.
insert mode:
As mentioned earlier, as soon as you open vi editor, it is
on command mode. To switch to insert mode, type
or press "i"
We will discuss about below characters(insert mode commands),
there are more than these which you can practice as per your need . Each
character does its unique function.
We will discuss about "i", "I", "o",
"O", "a", "A", "s", "S",
"C","~", "r"
The functions of each character are mentioned below:
From command mode ,
press "i " , in the insert mode, what ever text you enter , will be inserted
just before the cursor position ,ie, the
text will be added infront of the cursor moving the cursor to the right.
From command mode ,
press "I " , the cursor moves to the start
of the line and if you enter the text, they will appear in front of the cursor.
From command mode ,
press "o" , a new line will be added just below the line at which
the cursor was there previously. Now, the cursor moves to the beginning of the new line.
From command mode ,
press "O" , a new line will be added just above the line at which
the cursor was there previously. Now, the cursor moves to the starting of the
new line.
From command mode ,
press "a" , the entered
text will be added after the original cursor position.
From command mode ,
press "A" , the cursor moves to the end of the line and the
entered text will be added at the end of the line.
From command mode ,
press "s" , the highlighted character , ie the character at which
the cursor is residing , will be deleted.
From command mode ,
press "S" , the entire line at which the cursor is residing will
be replaced as blank. And the cursor will be at the beginning of the line.
From command mode ,
press "C" , the entire text of the line on the right side of the
cursor including the character at which the cursor was residing will be deleted.
From command mode ,
press "~" , the case of that character which the cursor is
highlighting will be changed ,ie, if lower then will be changed to upper and if
upper then will be changed to lower.
From command mode ,
press "r", you will see a
text " -- REPLACE --" at the bottom of the editor. Press ENTER, the
cursor along with the text on right side including the text at which the cursor
was previously, moves to the new line.
From command mode , press "r", you will see a text " -- REPLACE --"
at the bottom of the editor. Press any character , that character will replace
the existing text .
This way you can practice with other insert mode commands ,upper case and lower case, as per your need.
Command mode
We will discuss about below commands(in command mode):
h , l , j , k , L , H , M , G , 3G , w , :n , :$ , 0 , x , dd
, yy , p , u , ^ , $ , /search , n , ?search , N , := , :.= , :f , keyboard keys(CTRL + U/D/F/B/H/M)
h --- moves the cursor to the left , one character each time you press
"h"
l --- moves the cursor to the right, one character each time
you press "l"
j --- moves the cursor one line down each time you press
"j"
k ---moves the cursor one line up each time you press
"k"
Note : you can use your keyboard arrows also to move the
cursor to the left, right, up, down
L --- moves the cursor to the beginning of the last line on
the screen
H --- moves the cursor to the beginning of the first line on
the screen
M --- moves the
cursor to the beginning of the middle line on the screen
G --- moves the cursor to the beginning of the last line of
the file
3G --- moves the cursor to the beginning of the 3rd line of
the file, you can give any number with the letter "G" and the cursor
moves to the respective line of the file.
w --- moves the cursor to the beginning of the next word on
the right side.
:n --- :3 will move
the cursor to the beginning of 3rd line, :6 will move the cursor to the
beginning of 6th line and so on.
:$ --- goes to beginning of last line.
0 --- moves the cursor to the beginning of the line(this is
zero not the character "o").
x --- deletes the character which the cursor is at ,ie,
which the cursor is highlighting.
dd --- deletes the entire line at which the cursor was there
and the below line moves one step up and the cursor is at the beginning of that
line.
yy --- copies the line at which the cursor is .
p --- paste the copied line just below the line at which the
cursor is .
P --- paste the copied line just above the line at which the
cursor is .
u --- this will undo
the activities done previously. Press "u" more , more previous
activities will be undone.
^ --- cursor moves to the front of the line
$ --- cursor moves to the end of the line.
/text press
ENTER --- searches the text in clockwise
direction , ie, from left to right and if the cursor does not find on the right
side then the first word from the top.
n --- when you search
the text using "/text" and pressing ENTER, once ENTER is pressed now
to search another occurrence of the same text just press "n" ,ie,
repeat the last search forward.
?text and press ENTER --- when you type ?text and press
ENTER , you search the text in backward direction , ie, right to left and in
the anti-clockwise direction . And pressing "n" in this situation ,
searches the next occurrence of the same text in backward direction, ie, repeat
the last search backward.
N --- as discussed above, pressing "n" will repeat
the previous search forward or backward. After searching the text , pressing
"N" will do the search in opposite direction of "n".
:= --- displays the
total number of the line
:.= --- displays
current line number
:f --- shows file name and the current line of the cursor
and total lines.
Keyboard keys
CTRL+u(or U) --- To scroll the screen half up
CTRL+d(or D) --- To scroll
the screen half down
CTRL+f(or F) --- To move
forward by one screen
CTRL+b(or B) --- To move
backward by one screen
CTRL+h(or H) --- moves the cursor one step back ,if at the
beginning of the line , then it moves to the end of upper line.
CTRL+m(or M) --- moves the cursor one step forward ,if at the end of the line , then it moves to the beginning of the below line.
No comments:
Post a Comment