One thing I wish I had when first starting with Linux was a
page explaining only the commands absolutely necessary for
using vi. So, for the really green newbies (my green has
faded abit) I've written a short primer.
All you really need to know about vi
Okay, it wasn't as easy as you hoped, but you finally got
Linux installed after much wailing and gnashing of teeth.
You try to start KDE, a whole bunch of messages fly by, and you
wind up back at the command prompt. So you ask the good
folks on the COL users mailing list "What do I do now?", and as
usual they make some helpful suggestions which probably involve
editing the XF86Config file.
Grateful that you have some ideas to try, you go back into
Linux and, "Now what?" you probably think. Yes, it's time
to edit a file, from the console. One program to do this
which is installed on probably every Linux and Unix machine is
called vi. With it, you can edit any text file on the
computer, without the need for a GUI or a mouse. And
while there are many commands and functions which can be
done with the appropriate combinations of keystrokes, there
are only a very few which are really needed to edit a text
file.
First, _backup_the_file_you_want_to_edit_. This is done with the copy command, cp. Give the file an extension which will let you know that it is the original file. For example, in the case of XF86Config, type:
cp XF86Config XF86Config.orig
and hit <Enter>. Now, if you really mung up the file while editing, you have the original to fall back on.
Now, we edit. For example, to edit the file XF86Config, type:
vi XF86Config
and hit <Enter>. The contents of the file will appear, and at the bottom of the screen you will see "XF86Config" NN lines, NNN characters. (N is some number.)
Now you can use the arrow keys and <Page Up> and
<Page Down> to move around in the file. When you
get to the line you want to edit, hit the 'i' key (for
Insert.) At the bottom of the screen, you will see
-- INSERT --. Now you can type in what you want.
The delete and backspace keys will remove characters, as you
probably guessed.
A word of warning - if you hit some other letter key before you hit 'i', strange things might happen. Just remember, before typing anything, hit the 'i' key.
But what if you forget, and strange things happen?
Being new to Linux and vi, you don't know what happened or why,
you're confused, and you just want to bomb out of the program
without saving the file. Hit the <Esc> key.
The bottom of the screen where it said -- INSERT -- will
go
blank. Now, type : (that is, a colon.) At the
bottom of the screen, you will see a colon (:). Type
q!
and hit <Enter>. You will be back at the console command prompt, and you can start again.
Once you've made the changes you wanted, hit <Esc>. Then type
:wq
and hit <Enter>. The file will be written to the disk and you will quit vi. To save the file without quitting, leave out the 'q'.
That's it! All you really need to know about vi to edit a file.
So, to summarize without all the extra verbiage:
1. To create or edit a file, enter:
vi filename
2. To move around, use the arrow keys, <Page Up> , <Page Down>.
3. To enter text, first type the i key.
4. To delete characters, use the backspace and delete keys.
5. To quit without writing changes, hit <Esc>, and enter
:q!
6. To write changes without quitting, hit <Esc>, and enter
:w
7. To write changes and quit vi, hit <Esc>, then enter
:wq
8. And when you want to learn more about vi, enter
man vi
at the command prompt.
|
|
|