[Gllug] Learning Vi/Vim

Kieran Barry kieran at esperi.demon.co.uk
Fri Dec 21 21:42:38 UTC 2001


On Thu, 20 Dec 2001, harry wrote:

> I was completely confounded by Vi until I had the opportunity to sit with 
> someone who had the time and patience to teach me a few of the commands and 
> show me what is what. I now think that Vi/m is the best thing since sliced 
> bread, I find it easy simple and fast for a non touch typer. I know that a 
> lot of people instantly dismiss Vi as hard to use. My recommendation is to 
> wait until you have the opportunity to sit (pyhsicaly with someone) and ask 
> the questions to learn how to use this great tool. I am also looking forwad 
> to learning Emacs but I need the same environement as before,  I need someone 
> to show me. When on ones own its a pigs ear of a job trying to learn a text 
> editor + linux etc etc . 
> 
There are probably lurkers out there who don't grok vi yet.

I hacked up the following a while back, but never gave it to anyone.
Which makes it a waste of time.  Anyway, there's nothing in it that
someone who's used vi for a while doesn't know, but I wish I'd had this
info to hand when I was starting out.

Regards

Kieran
-- 
Title: Another Perspective on VI


Philosophical Bit

The standard Unix text editor is vi.  It's a remarkably powerful tool,
but it has grown from another age of computing, one that predates graphical
interfaces.  Just as a modern child would be confused by the handles of 
a scythe, it takes some thought to understand vi.

Vi was a bolted-on extension to a line editor called ex.  It retains the
"edit command" perspective it inherited from ex. Vi is much easier to
use when you understand this perspective.  In particular, inserting
text is a command.  Saving or quitting is not possible until you
terminate the edit command by hitting ESC.  This is the biggest tip
you'll ever get with vi.  

Practical Bit

Command mode

Vi's default is command mode. This is the situation you find yourself in
when the editor starts. When inserting, you can return to command mode
by hitting ESC. Command mode allows access to movement, searching,
advanced editing commands, saving, exiting or inserting text.

Obviously, the most important commands are to save and to exit.
:q	:	Quit (if you've made a change see next...)
:q!	:	Quit and abandon changes.
:w	:	Write file to disk. Useful if you're editting an
		existing file
:w <file>:	Write to <file> on disk.  <file> is optional.
:w! <file>:	Overwrite file on disk. <file> is optional.
:wq	:	Write to file and exit. Far and away the most useful of
		this commands!

Insert mode

Insert mode can be entered a number of ways. I,i,A,a,S,s,R and c all
enter different variants of insert mode. Once in, you just type. To exit
insert mode, hit ESC.

Most important:
i	:	inserts text at the cursor
a	:	inserts text after the cursor
I	:	inserts text at the beginning of the line
A	:	inserts text at the end of the line.
R : Replace text.  This overwrites...
Note: to put text at the end of the line, you need to use 'a' or 'A'.

Vi is much easier to use if you get into the habit of pressing ESC
whenever you pause for thought.

Movement

Vi has more movement commands than you can shake a stick at. I'm a
useful vi user, with a couple of years experience. Below, I outline the
movement commands I use, in decreasing order of importance.

The cursor keys will normally work in Linux, (even in insert mode) but
this behaviour cannot be relied on on many UNIX systems. The standard
movement keys are:
		Up
		k
	Left  h	  l Right
		j
		Down
These only work in command mode.
CTRL-f 	: 	Goes forward one screen
CTRL-b	:	Goes back one screen
$	:	Goes to end of line
^	:	Goes to beginning of line
w  	:   	Goes one word forward
b  	:   	goes one word back

Deleting text

x	:	Delete the character under the cursor (like the delete key in windows.
X	:	Delete the character before the cursor (like backspace or <- in windows.)
dd	:	Delete the current line


Comment on how to improve this document is welcome at
kieran at esperi.demon.co.uk
This text is copyright Kieran Barry 2001.
Permission to reproduce this document in its entirety is granted.
Out of politeness, I'd like if you could mail me at the above address if
you do use it.




-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list