Vi Editor On Linux

In Vi editor we have 3 modes :

1)command mode
2)insert mode
3)execute mode
In command mode we can copy,paste,delete,undo,redo,move,save&quit

In insert mode we can only edit data

In execute mode we can set line numbers,delete line numbers,save&quit,quit with out   saving,substitute data

when ever we type vi
if the file is there it will edit the existing file
if the file is not there it will create a new file
by using vi it will enter into command mode

to go to insert mode from command mode
i: insert text at current cursor position
I: insert text at the begining of cursor line
a: append text after cursor position
A: append text at the end of cursor line
o: create a new line below cursor line and append text
O: create a new line above cursor line and append text
s: it removes cursor presented character and append data
to move from insertmode to command mode press “esc key”

1).Command mode :

dd: to delete a line
5dd : to delete five lines
yy: to copy a line
5yy: to copy five lines
p: paste
10p : paste 10 times
ctrl+r :redo
shift+g or G : to move last line of a file
gg :to move first line of a file
10g :to move 10th line of a file
shift+zz : save&quit
to move into execute mode from command mode press shift+:

2).Execute mode :

q: quit with out saving
q!: quit with out saving forcefully
wq: save&quit
x: save&quit
wq!: save&quit forcefully
:/ : to serach for a particular word
ex: /sun : searching for a word sun in the file
:15 :to jump into 15th line of a file
set nu: to set line numbers for a file
set nonu: to remove line numbers of a file

3).Substitution(Insert mode) :

syntax: , s ///g
ex: if i want to change LABEL as SMS in /etc/fstab
1,$ s/LABEL/SMS/g
here 1,$ indicates from first line to lastline
s for substitute
LABEL is old charcter
SMS is new character
g for grouping
note: to set automatic line numbers
crate a hidden file as follows in /root
vi .vimrc
(type) set nu
save& quit
to create hidden files in linux use . at the begining of filename
ex: cat > .sun
now .sun is a hidden file
clear : used to clear the screen or use ctrl + l