Difference between revisions of "Vi"

From Hackepedia
Jump to navigationJump to search
 
Line 27: Line 27:
  
 
but watch for errors like file permission issues. The ! forces the changes to be made.
 
but watch for errors like file permission issues. The ! forces the changes to be made.
 +
 +
 +
vi +/beer .procmailrc
 +
 +
this will open the file procmailrc and bring you to the first instance of the word beer. The same as opening .procmailrc in vi and doing /beer [enter].

Latest revision as of 16:40, 4 April 2006

For some reason you have to edit a file on unix, and have never done so before, and the only editor around is "vi". We'll use httpd.conf and the example file to edit:

vi httpd.conf

this opens the file in command mode, assuming you're in the directory that contains httpd.conf. The other mode is insert mode, where we want to insert text. so we type

i

and now we're in insert mode. We can move throughout the text and edit as we please. If we make a typo we hit the ESCape key to go back to command mode and type

:u

which means undo last edit. If you've made a few mistakes and want to start over

:e 

will do this. Remember to hit "i" to get back into Insert mode to edit again.


Once you're happy with your changes, hit ESCape to get back to command mode and then:

:wq! 

will force the changes to be saved to disk. I would recommend trying it without the ! and just do

:wq

but watch for errors like file permission issues. The ! forces the changes to be made.


vi +/beer .procmailrc

this will open the file procmailrc and bring you to the first instance of the word beer. The same as opening .procmailrc in vi and doing /beer [enter].