Vi

From Hackepedia
Revision as of 21:03, 30 October 2005 by Frankk (talk | contribs)
Jump to navigationJump to search

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. 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.