Following tutorial will guide you through mastering Vi Editor in the simplest possible way -
1. Opening a file in Vi Editor -
vi <file name>
vi -r <file name> [useful if the file was not saved earlier because of sudden connection failure]
2. Quit and save a file in vi editor -
:q [wuit without saving]
:wq or :x [quit after saving the changes]
:w <file name> [to save a file with new name]
3. Traversing a file in vi -
k or <up arrow> [to go up]
j or <down arrow> [to go down]
h or <left arrow> [to go left]
l or <right arrow> [to go right]
4. editing in vi editor -
i [replace charactor after cursor untill esc is pressed]
a [replace charactor before cursor untill esc is pressed]
r [replace the charactor where cursor is right now]
R [replace the chars starting the cursor position, untill esc is presses]
x [delete the charactor where cursor is right now]
dd [delete entire current line]
ndd [n is a number, delete n following lines in cluding current]
D [delete the line after cursor]
o [place a new line after current line to enter text untill esc is pressed]
O [place a new line before current line to enter text untill esc is pressed]
C [change the char in current line untill esc is pressed]
cc [ehcnge entire line]
yy [copy current line into buffer]
p [paste the text from buffer]
u [undo, but effective till one last change only]
5. Search and Replace in vi editor -
/String [search String forward]
?String [search String backward]
:%s/term1/term2/g [replace term1 with term2 in entire file]
Hope this will help you with vi editor.
No comments:
Post a Comment