Wednesday, April 14, 2010

useful Vi editor commands - text replacement and etc VISUAL BLOCK editing

==============VI COMMANDS===========================================


:80,90s/text/replacetext/g -- command to replace a text within certain lines


:70,99w >> filename (to append text from a file betn line nos to filename )


:n1,n2w file Write lines n1 to n2 to file


:n1,n2w >> file Append lines n1 to n2 to file


:1,10w file write lines 1 through 10 to file newfile


:340,$w >> file write lines 340 through the end of the file and append to file newfile





:33,224s/^/hh/ - insert the string 'hh' at the beginning of lines


:33,224s/$/hh/ - insert the string 'hh' at the ending of lines




:g/read/p - prints all occurances of `read' [kind of like a Unix grep]



% Display current filename





CTRL G shows the total no of lines in a file



:%s/text/replacetext/g to replace text


:uparrow for the above replacement command



:3,18d delete lines 3 through 18


ln -s file_name link_name





gf to move to a file in vi editor to come back type :bd or :e#


cat encounter.log
grep error
more


(VISUAL BLOCK) CTRL-V select lines to place text and type SHIFT I and type text u want and press escape

No comments: