Saturday, August 8, 2020

vi editor in linux

 

vi editor in linux

-------------------

vi editor introduction

-------------------------

vi editor is a visual text editor ,the default editor comes with unix operating system,unix vi editor is a full screen editor ,two modes of operation command mode and insert mode ,vi editor is free and open source ,vi uses less amount of system resources,vi supports all programming languages and differnt file formats also,vi is interactive text editor that is display oriented,using vi you can insert text anywhere in the file very easily.


To launch the vi editor open the terminal 


vi <filename_new> or <filename_existing>


vi chaitanya.txt



vi editor commands

-----------------------


i----->insert at cursor (goesinto insert mode)


a----->writes after cursor (goes into insert mode)(append after cursor)


A------>write at the end of the line (goes into insert mode)(append after line)


esc---->terminate insert mode


u------>undo last change


U------>undo all changes to the entire line


o------> open a new line (goes into insert mode)


O ------> open a new line before current line



Deleting Text

-----------------


dd------>delete line


3dd-----> delete 3 lines


D------->delete contents of line after the cursor


c------->delete contents of line after the cursor and insert  new text .press esc key to end


d$ -----> deletes from the cursor to the end of the line


ndw ----->deletes the next n words starting with current


ndb -----> deletes the previous n words starting with current


ndd -----> deletes n lines begginning with current line ,suppose we want to delete 100 lines then 100dd


nmd ------>deletes lines n through m



Insertion

-------------

dw------>delete word


4dw------>delete 4 words


cw------->change word


x-------->delete character at the cursor


r-------> replace character


R-------> overwrite characters from cursor onward


s------->substite one character under cursor continue to insert


S------->substitute entire line and begin to insert at the begining of the line


~------> change case of individual character


:r ----->file reads file and inserts it after current line


:nr ----> file reads file and inserts it after line n


p -----> put after the position or after the line


P ------> put before the positionor before the line



Moving cursor with in a line

-------------------------------------

K ------>move cursor up


J------->move cursor down


h------->move cursor left


l------->move cursor right


w ------> move to the next word


W -------> move to the next blank delimited word


E--------> move to the end of blank delimited word


O or | ----> move to the beginning of the line


n| ------> moves to the column n in the current line


$ -------> move to the end of the line


1G -----> move to the firstline of file


G -------> move to the last line of the file


nG ------> move to the nth line of the file suppos eyou want to move to 100 th line then 100G


n ------> move to the n th line of the file


H ------> move to top of screen


nH -----> moves to nth line from the top of the screen


M ------> move to middle screen



Searching for Strings

-------------------------

/string -----> search forward for string like error


?string ----> search bak for string


n ------> search for next instance of string


N ------> search for previous instance of string


% ------> search to begining of balancing(){} []


?str ----> finds in reverse for str


/fmw_home  -----> search forward for fmw_home in the file


?fmw_home ------> search backward for fmw_home in the file


n ------>repeat previous search


N ------> repeat search in opposite direction


/.? -----> repeat search forward or backward 



Replace or substitution

-----------------------------

 The search and replace function is accomplished with the :s command. it is commonly used in combination with ranges or the  :g command(below)


:s/pattern/string/flags replace pattern with string accordingto flags


g Flag ---> repalce all occurances of pattern


c Flag ----> Confirm replaces


& Repeat last :s command


it can be used like this also 


:s,pattern,string,flags


:s^pattern^string^flags


:s^/oracle^/java^g  ----> This will replace /oracle with /java every where in the file 


s,^a,^b,g -----> this will replace  ^a with  ^b everywhere in the file



Saving and closing the File

---------------------------

shift++zz ----->save the file and quit


:w -----> save the file but keep it open


:w! -----> saves current file overriding normal checks but doesnt exit


:q ------> quit without saving


:q! -----> quits vi and without saving ifyou have done some mistake and want to quiy without making any changes


:e! ----->edits file discarding any unsaved changes(starts over)


:we! ----> saves and continues to edit current file


:wq-------> save the file and quit



Yanking Text

----------------

yy -----> yank the current line


:y -----> yank the current line


nyy or nY -----> places n lines in the buffer -copies





THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME 


ITIL Process

ITIL Process Introduction In this Blog i am going to explain  ITIL Process, ITIL stands for Information Technology Infrastructure Library ...