It is probably the oldest widely-used editor
It is used in every UNIX establishment in the world.
It runs on every platform in the world.
If it suits you, it is a very good editor. If not it
is the only emergency editor you've got.
Making Vi easier to start with
Input the following UNIX command
~dick/bin/Q noviceand you will reprogram vi to start in novice mode. vi will continue in this mode until you:
rm .exrc; ~dick/bin/Q setupor until you change '.exrc' in some other way.
You type in commands. Some commands let you input characters. The input characters end when you tap the esc key.
Commands are keystrokes:abcdefg...ABC....Z(){}$0!/?<>...
You can not, on a networked connection trust use the arrow keys. The are transmitted as a sequence of characters and there can be a delay.
Do these exercises slowly once.
And then repeat more quickly. The goal is learn the key strokes not
to finish quickly. -- vi is the thinking person's editor. You need
to train your fingers to drive the editor.
Exercise 1: Getting started
Put a piece of paper over the arrow and number keys!
Hide that mouse!
In a terminal window ('xterm' is best) or on a terminal at home, at the unix prompt type in the following: (esc means tap the Esc key, Tap return at the end of each line).
vi ex
iThis is some input.
And here is some more.esc
:q!and repeat the exercise from the beginning.
You have just used the 'i' command to input some text. Next you will go up to the first line, delete the first line and then paste it back as the last line:
kddp
Do the same keys again and watch: k = up, dd = delete line, p=paste after.
We will now delete the word 'And' and change the 'h' to 'H':
dw~
We will no Go to line 1:
1G
We will now find the word 'some' and delete it.
/some
dw
We will not do the same thing again - find next 'some' and delete it:
n.
Now put it back by undoing the delete: u=undo
u
We will now undo the undo:
u
(If you hold down 'u' the word will be inserted and deleted repeatedly)
We now find can change the word 'input' to 'text':
/input
cwtextesc
Add a line at the end of the file:
GA
These are the last two
lines in the file.esc
We now save (write) the file and quit(exit):
:wqUnix Prompt...
cat ex
You've just used these commands:
Remove the ex file and repeat the above exercise.
Exercise 2: Input and Sort a file
Input the following and see watch what happens:
vi ex2
iSpot
Dick
Janeesc
1G!Gsort
:wq
Exercise 3: Adding data
Use these keys in vi to add numbers to 'ex2' file:
vi ex2return
A 122-45-6789escreturn
A 123-45-6789escreturn
.:wqreturn
You should end up with:
Dick 122-45-6789
Jane 123-45-6789
Spot 123-45-6789
Adding new lines:
vi ex2return
oDoc 987-65-4321return
John 987-65-4321esc
:wreturn
Sorting the data again:
1G!Gsort
:wqreturn
This is an exercise in moving the cursor around, one character at a time, without using the arrow keys. First we input and save a 100><100 grid of plus signs - in fact 10 lines each with 10 plusses:
vi grid
10i+esc
..........
:w
Put a finger above the 'k' and watch what happens as you push it 10 times. Then watch what happens when you tap the 'l' key 10 times. Then do 10 j's and then 10h's. Repeat this three times, speeding up as you go. It should teach your fingers about left-down-up-right movements of the cursor.
You can also repeat most commands without typing them in many time:
10k10l9j10h
You can replace a plus sign on the screen by another character using the r command followed by the new character... for example: (with no return at the end...)
5k5lro
So by moving around the grid an replacing characters can you make a drawing of something? A face, a traffic sign. etc?
You can save the your picture at any time by
:w(with return) You can quit by
:q
You can post the saved file on the BBS... and you can even send it directly to the BBS like this:
1G!Gpostwhich reads:
Exercise 5: Cursor Movements and gemini:/usr/games/hack
The exists a game that uses the same cursor keys as 'vi':
You will be shown a map of parts of a dungeon on the screen and each time you tap a key it will be read as a command. The commands move you about the dungeon, attack monsters, and pick up various things. It has lots of variations. The original was called 'rogue', a later one was called 'urogue' and the 'hack'. These days you can download 'nethack' (an open source version) for Windows etc.
Hint: Don't kill the little dog or pony.
Exercise 6: Handling words
This exercise is about moving about a piece of text
one or more words at a time, and changing one or
more words. The commands are
Input the following as shown below, including tapping the Return key at the end of each line:
vi words
iThe quick brown fox jumps over the lazy dog.
Pack my box with five dozen liquor jugs!
Now is the time for all people to come to
the aid of the party.esc
kkkkYou should now have the cursor at the start of the text. We will first slow down the fox and then speed up the dog: (NO returns at end of line below...)(watch what happens as you type this... but don't react to it)
wcwlazyesc
6wcwquickesc Did you notice how the change command 'c' put a dollar sign at the end of the word being changed?
The following shows how 'b' is used...
bbbbbbcwquickesc
Next we will apply prohibition to our jugs:
+6wdw
Now a little experiment. watch what happens when you tap the 'w' key until you get to the end of the file, and then 'b' until you get back to the beginning... Answer this question: Are punctuation marks like "!" and "." treated as words or as part of words?
6 Free Practice.
Use the key commands covered in these exercised to
create a message celebrating you newly learned skill
and post it on the bulletin board BBS. Keep it short
and clean!
Special symbols in these exercises
. . . . . . . . . ( end of section Beginning Vi) <<Contents | End>>