Skills You Should Know (SYSK) – vi

I’m starting a new category, that goes along with my blog post
Yes I will lead. The new
category is called Skills You Should Know – SYSK. Little bits of
information that through my experience aren’t something that you may not
necessarily use every day, but may someday save you a ton of trouble.

Today’s topic is vi.
Vi may be the only editor
installed on a new unix based system, and a few commands will get you to
the point where at least you can edit a few files before installing
something a little more user friendly such as pico (or nano).

Vi has two modes, command and insertion. It was designed this way
because sometimes the keyboard you would be using might not necessarily
have all the keys we take for granted today, especially when it comes to
the arrow keys. In command mode you can move the cursor around with the
arrow keys or hjkl keys. To do an editing, you’ll need to switch to
insertion mode. Vi defaults to command mode when it is started.

i – Switches to insertion mode
\ – Switches to command
mode

In a nutshell, you’ll start the editor with a file:

vi somefile

Once the file is open, you’ll press
i to switch to insertion mode.
Make the changes to your file. Press
\ to switch back to command
mode. To exit you’ll press the following (these all start with the
colon):

:wq – Write the file and then
quit
:q! – Quit the file without
saving the changes. A great way if you mess up and just want to not save
your changes

These preceding commands should at least get you started. For more info,
you may want to visit the following pages:
vi – Wikipedia, the free encyclopedia
Vi Cheat Sheet
Mastering the VI editor