Tuesday, March 11, 2008

Installing FreeBSD 7.0 - Using VI

Creating new file:
  • Execute: cd ~/ (walk to your home folder)
  • Execute: vi testing
You are now in the VI-editor.

First: If you for some reason think that you have destroyed the file that you are editing and just want to quit as fast as possible without saving anything, do this:
  • Press: ESC
  • Press: corresponding key for character ":"
  • Write: q! and press enter
This will exit VI without saving.

Vi works in three modes. Edit mode, strange mode and command mode. The strange mode is what mode VI starts with.

Be careful, you can do harmful stuff in all modes. When you are in strange mode you can do the following:
  • Press "i" to enter edit mode
  • Press ":" to enter command mode
When in edit or command mode you can always press ESC to return to strange mode.
Sometimes when you update text in edit mode, your changes doesn't seem to appear. Press left or right arrow key, and the text will be updated if any changes were made.

In strange mode (remember the ESC-key) you can use the Delete key. Which I find impossible to use in edit mode.

Adding new text will easily be performed in edit mode (remember the "i" key)

Now you want to save this file:
  • Enter "the other mode" with ESC if not already there
  • Press the corresponding key to get a ":". This will give you command mode.
  • You will now have a : at the bottom of the screen which will await your command.
  • Write "w" and press enter. Your file will be saved.
  • Write "q" and press enter. You will exit VI.

No comments: