DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.


Basics of Vi editor in UNIX

Vi is present on any Unix installation and it is therefore useful to know some basic
commands. There are two modes: command mode and insertion mode. The commands mode is
accessed with [ESC], the insertion mode with i.appending mode with a .

Quit

:w                      
newfilename save the file to newfilename
:wq or :x            
save and quit
:q!                     
quit without saving


Search and move

/string                
Search forward for string
?string               
Search back for string
n                      
Search for next instance of string
N                     
Search for previous instance of string
{                      
Move a paragraph back
}                      
Move a paragraph forward
1G
Move to the first line of the file
nG
Move to the n th line of the file
G
Move to the last line of the file
:%s/OLD/NEW/g
Search and replace every occurrence

Delete text


dd
delete current line
D
Delete to the end of the line
dw
Delete word
x
Delete character
u
Undo last
U
Undo all changes to current line





Do you like this story?

No comments:

Post a Comment