.Open Beginning Vi . Facts `vi` is designed for good typists. .Box Cursor movements are done by typing normal characters. Commands are done by typing normal characters. Text is input by typing normal characters. .Close.Box .Box No mouse needed. No menus needed No special keyboards... just a typewriter keyboard No windows needed What you type is not what you see, and not what you get! .Close.Box 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 .As_is ~dick/bin/Q novice and you will reprogram vi to start in novice mode. `vi` will continue in this mode until you: .As_is rm .exrc; ~dick/bin/Q setup or until you change '.exrc' in some other way. . Introduction You can not input characters until you type the 'i' for input command. 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). .As_is vi ex .As_is iThis is some input. .As_is And here is some more. `$esc` .Box If you forgot the 'i' on the second line above then then you will get a few beeps and the text "s is some input..."! The best thing to do is to exit 'vi' discarding the text: .As_is :q! .As_is and repeat the exercise from the beginning. .Close.Box 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: .As_is 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': .As_is dw~ We will no Go to line 1: .As_is 1G We will now find the word 'some' and delete it. .As_is /some .As_is dw We will not do the same thing again - find `n`ext 'some' and delete it: .As_is n. Now put it back by undoing the delete: u=undo .As_is u We will now undo the undo: .As_is u (If you hold down 'u' the word will be inserted and deleted repeatedly) We now find can change the word 'input' to 'text': .As_is /input .As_is cwtext `$esc` Add a line at the end of the file: .As_is GA .As_is These are the last two .As_is lines in the file. `$esc` We now save (write) the file and quit(exit): .As_is :wq Unix Prompt... .As_is cat ex You've just used these commands: .Box A=Add After line. cw=change dd=delete line i=insert k=up G=Goto n=Next u=undo w=word :wq=write and quit /=search .=do-it-again ~=change upper case to lower case and vice versa. .Close.Box Remove the `ex` file and repeat the above exercise. . Exercise 2: Input and Sort a file Input the following and see watch what happens: .As_is vi ex2 .As_is iSpot .As_is Dick .As_is Jane `$esc` .As_is 1G!Gsort .As_is :wq .As_is . Exercise 3: Adding data Use these keys in vi to add numbers to 'ex2' file: .Box `$return` = goto next line A = Add At end of Line . = do it again `$esc` = end my added text .Close.Box .As_is vi ex2 `$return` .As_is A 122-45-6789 `$esc``$return` .As_is A 123-45-6789 `$esc``$return` .As_is .:wq `$return` You should end up with: .As_is Dick 122-45-6789 .As_is Jane 123-45-6789 .As_is Spot 123-45-6789 Adding new lines: .As_is vi ex2 `$return` .As_is oDoc 987-65-4321 `$return` .As_is John 987-65-4321 `$esc` .As_is :w `$return` Sorting the data again: .As_is 1G!Gsort .As_is :wq `$return` . Exercise 4: Cursor movements 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: .As_is vi grid .As_is 10i+ `$esc` .As_is .......... .As_is :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: .As_is 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...) .As_is 5k5lro .Box Goes up 5, right 5 and replaces the character by a 'o'. .Close.Box 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 .As_is :w (with return) You can quit by .As_is :q You can post the saved file on the BBS... and you can even send it directly to the BBS like this: .As_is 1G!Gpost which reads: .Box 1, GO Escape Go to end post it .Close.Box . Exercise 5: Cursor Movements and gemini:/usr/games/hack The exists a game that uses the same cursor keys as 'vi': .Box h::vi_movement=left. j::vi_movement=down. k::vi_movement=up. l::vi_movement=right. .Close.Box (So does the WWW browser 'lynx', the file browser 'less', etc...) The game is a distant ancestor of DOOM and QUAKE... you run about inside a dungeon destroying monsters, casting spells, collecting various things, and other kinds of fun. 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 .Box w = skip one word forward b = skip one word back + = start of next line dw = delete next word cw = change word .Close.Box Input the following as shown below, including tapping the Return key at the end of each line: .As_is vi words .As_is iThe quick brown fox jumps over the lazy dog. .As_is Pack my box with five dozen liquor jugs! .As_is Now is the time for all people to come to .As_is the aid of the party. `$esc` .As_is kkkk You 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) .As_is wcwlazy `$esc` .As_is 6wcwquick `$esc` 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... .As_is bbbbbbcwquick `$esc` Next we will apply prohibition to our jugs: .As_is +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 esc::=tap the Escape key. return::=tap the Return or Enter key. . See Also .See http://www/dick/doc/vi .See http://www/dick/doc/vi.commands .See http://www/dick/doc/vi.FAQ .Close Beginning Vi