Vi: Difference between revisions

From Hackepedia
Jump to navigationJump to search
Frankk (talk | contribs)
No edit summary
Frankk (talk | contribs)
No edit summary
Line 18: Line 18:




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


  :wq!  
  :wq!  

Revision as of 20:03, 30 October 2005

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.