jwas@PacBell.COM (Joe Wasik) (06/06/90)
From the users that we support and from new Unix users in general, we get many request for tutorials on vi. Our printed copy has been photo-copied so many times, it's barely legible. Can anyone help by sending us the nroff/troff source to such a tutorial? While beggars can't be choosy, we prefer something formal, e.g. a document written by vi's author or by AT&T. -- Joe Wasik - PacBell, 2600 Camino Ramon, 4e750, San Ramon, CA 94583 823-2422 jwas@pbhyf.PacBell.COM or {att,bellcore,sun,ames,pyramid}!pacbell!pbhyf!jwas "I have good news. You're favorite gum is coming back in style" -- The Dancing Dwarf
fyl@ssc.UUCP (Phil Hughes) (06/08/90)
In article <7586@pbhyf.PacBell.COM>, jwas@PacBell.COM (Joe Wasik) writes: > From the users that we support and from new Unix users in general, we get many > request for tutorials on vi. Our printed copy has been photo-copied so many > times, it's barely legible. ... I don't have a free and available VI Tutorial but we do publish a pocket-sized tutorial on VI that might be of interest. It is about 60 pages and complements our VI Reference Card. The VI Tutorial is based on material we use in our Hands-On classes. It was written by Belinda Frazier, the instructor of the beginning class. For those unfamiliar with our products, we have been publishing UNIX reference materials since 1983. The are all pocket sized (8-1/2" by 3-1/2"), vary in size from an 8-sided card to 64-page books. If you need more info, you can call, E-mail, FAX, write or just about anything else and we can send you our newsletter/flyer called _The UNIX Pages_. -- Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155 (206)FOR-UNIX uunet!pilchuck!ssc!fyl or attmail!ssc!fyl (206)527-3385
maart@cs.vu.nl (Maarten Litmaath) (06/08/90)
In article <7586@pbhyf.PacBell.COM>, jwas@PacBell.COM (Joe Wasik) writes: )From the users that we support and from new Unix users in general, we get many )request for tutorials on vi. Our printed copy has been photo-copied so many )times, it's barely legible. ) )Can anyone help by sending us the nroff/troff source to such a tutorial? )While beggars can't be choosy, we prefer something formal, e.g. a document )written by vi's author or by AT&T. The official BSD vi documentation can be retrieved through anonymous ftp from star.cs.vu.nl (cd pub/maart): Vi-BSD-doc.1 Vi-BSD-doc.2 Vi-BSD-doc.3 These files contain ^G characters, so use binary mode. The files are redistributable under the terms of the copyright notice they contain. Also present: vi.ref - Vi Reference vi.ref.nl - Dutch variant macro-guide - a guide to vi macros -- "COBOL is the revenge of some witch burned |Maarten Litmaath @ VU Amsterdam: in Salem, [...]" (Bill Davidsen) |maart@cs.vu.nl, uunet!cs.vu.nl!maart
UH2@psuvm.psu.edu (Lee Sailer) (07/16/90)
Can someone email me a good VI tutorial? I am teaching half a dozen Unix novices vi. TeX LaTeX preferred, but hey, I'll take anything. lee
maart@cs.vu.nl (Maarten Litmaath) (07/17/90)
In article <90196.154016UH2@psuvm.psu.edu>, UH2@psuvm.psu.edu (Lee Sailer) writes: )Can someone email me a good VI tutorial? I am teaching half a dozen )Unix novices vi. TeX LaTeX preferred, but hey, I'll take anything. Try anonymous ftp to star.cs.vu.nl (192.31.231.42), directory `pub/maart'. Some of the contents (see the `README' file): Vi-BSD-doc.1 - official Berkeley Vi documentation, part 1 of 3 Vi-BSD-doc.2 - official Berkeley Vi documentation, part 2 of 3 Vi-BSD-doc.3 - official Berkeley Vi documentation, part 3 of 3 macro-guide - a guide for writing Vi macros macro-tips - a few tips concerning Vi macros vi.ref - the Vi Reference vi.ref.nl - Dutch variant of the Vi Reference If ftp doesn't work for you, I can send you the stuff by email. -- "and with a sudden plop it lands on usenet. what is it? omigosh, it must[...] be a new user! quick kill it before it multiplies!" (Loren J. Miller)
UH2@psuvm.psu.edu (Lee Sailer) (07/18/90)
Thanks to the people who responded to my request, I now seem to have what I need. I also wrote an online tutorial similar to the one I from my old EMACS days. (I got a similar one from Robert Drabek.) Just in case someone can use it, I am posting it here. ================== cut here ============================= W E L C O M E to V I Vi is a text editor that will be found on nearly all Unix machines you will ever encounter. Even if you find another editor you like better, it is handy to know vi for those occasions when you find yourself using another machine. More importantly, many other applications you will find on Unix machines model their user interface after vi (sort of like Lotus 1-2-3 on MSDos machines, without the lawsuits), so good vi skills will transfer to other programs, too. To learn vi (short for "visual"---people in the know say "vee eye") you can start by reading this file and trying the things that are suggested. You can't hurt the original file of this tutorial, so if you accidentally convert all the vowels to the Russian alphabet or something, don't worry. MOVING THROUGH THE FILE You can use ^U and ^D to move back and forth through the file. Try it a few times. They move by half screens. ^F and ^B move by full screens. You can go directly to the twentieth line by typing 20G (that's G, not g). Any line number will work. No line number defaults to the last line in the file. Try G and 1G, and then come back here for more. MODES in VI There are three "modes" of operation in vi. Right now you are in command mode. Everything you type will be interpreted as a command. Most editors treat the characters you type as text to be inserted, so this is one way that vi is different, and it takes some getting used to. In a minute, we'll see insert mode, which is how you create new text. The third mode is a line editor mode. MOVING AROUND THE SCREEN Another thing you need to know is how to move the cursor around the screen. The simplest way is to use the h, j, k, and l keys. They work like you'd expect arrow keys to work. Try typing the j key a few times now and see what happens. Then try h, k, and l, too. The j and k keys (up and down, right?) try to stay in the same column if they can, but will jump to the left if they encounter a short line that is not padded out with blanks. Also, if a line is so loooooooooooong that vi has to wrap it around so that you can read it (like this one), then it is still only one line, so that j and k will skip over the second part of it. Also handy are the 0 (zero) which moves to the start of a line, $ which moves to the end, and ^ (it's over the 6, usually) that moves to the first non blank in a line. Try typing 0, ^, and $ on this line to see how they work. Try the w, b, and e commands to move to the beginning of the next word, beginning of the previous word, or to the end of the current word. Now try typing the parentheses ( and ) and the braces { and }. They move by sentence and block of text, more or less. There are lots more commands like these, but that's enough for now. CREATING NEW TEXT The three most used commands for inserting new text into a file are i (insert), a (append), and o (open). When you type an i, vi starts inserting new text just before the place where the cursor is. REMEMBER that while you are inserting text, the commands we just learned in command mode no longer work. In insert mode, everything you type will be inserted as text. To get back to command mode, type the <esc> key. In other words, type an i, then some text, and then an <esc> to return to command mode. Try the i command now. Move up a few lines, type an i followed by some text, and then an <esc>, and see what happens. You can type pages and pages of text while in insert mode. The a command works the same way, except that it begins inserting text just after the cursor. The o command creates a new blank line just below the current line, and begins inserting text there. There is also an O command, that opens a blank line just above the current line. Try a, o, and O now. DELETING TEXT While you are in insert mode, the backspace key works the usual way. Also, ^W deletes the previous word, and your 'kill' character backs up to the beginning of the current line. (The kill character is usually @, but might be something else. Use stty -a to see.) Otherwise, to delete text you should usually be in command mode (so type <esc>). An x deletes the current character. Type dw to delete to the beginning of the next word, d) to delete to the end of the sentence, and d} to delete to the end of the block of text. In fact, a d followed by almost any cursor moving command such as b, e, or { will delete the stuff the cursor would have moved over. One that is not so obvious is dd, which deletes the entire current line. OOPS Some commands modify the text that you are working on. The u command will undo the most recent text modifying command. Especially useful when you accidently delete the 10 pages you just typed in. Just type u to get it back. STARTING a VI SESSION The command to start vi is $ vi [file ...] at the command prompt. You can type the names of zero or more files after vi. If you don't type any filename, vi will show you an empty buffer to work in, and you can write it to a file later. If you give it the name of a file that doesn't exist, it will create it for you. If you give vi more than one file name, you can edit them one after another. Vi does not modify the file on the disk until you tell it to do so. All operations are done on a copy of the file kept in main memory. Note that this sometimes places a limit on the maximum size file vi can handle, though it helps make vi pretty fast. ENDING a SESSION To modify the file on disk, so that it includes all your edits, you need to use the third mode, line editing. Type a : to enter line mode. To write the buffer out to the file, type a w, followed by a carriage return (or whatever it is called on your terminal). All the : commands need a carriage return at the end---look for <cr> in this tutorial. Vi does NOT repeat NOT NOT NOT make a backup copy of your file in its original state. As soon as you do the :w command, the original version of the file is replaced with the current version. If you want a backup copy, make one yourself with a command such as $ cp april.data april.data.bak You can even do this while in vi, before the first time you write with a :w by "forking a shell." The :! command allows you to execute any Unix shell command from within vi, so :!cp file file.bak<cr> will create a backup file, :!ls -l<cr> will show you a directory listing, and :!vi anotherfile<cr> will even start up another vi session in the middle of the current one. To exit from vi, use the :q command. If the file has been modified, vi will warn you. If you really want to quit without saving the modified file, add the "I really mean it" command like this :q!<cr> You can combine :w and :q into one command, :wq<cr> which will write the buffer and then quit. If you are editing a list of more than one file, you can go to the next with the :n<cr> command. At any time, you can write the current buffer into or over some other file by adding a filename to the :w command. If you want to write this buffer out to a file in your current directory named tutbuf, just use :w tutbuf<cr> SEARCHING The search commands are a handy way to make big jumps around a file. Searching can be done from wither command mode or line mode. In command mode, the / searches forward in the file and the ? searches backwards. Try typing ?tutbuf<cr> now, to search backwards for the string tutbuf. Vi remembers the last string you searched for, so now another ?<cr> will search again. The / works the same way in the forward direction. By the way, vi searches wrap around to the other end of the file when they hit the end. Suppose you wanted to go back to the section on delete. Just search for some pattern that you guess appears there---how about "delete"? Search for "delete" with /delete<cr> and see what happens. The pattern you search for can use the (almost) standard Unix pattern matching language. It is very powerful, so we won't consider it in detail here, but as useless but neat examples, /Th[^e]<cr> will search for any "Th" followed by any character except an "e", and /^[A-Z].*\. *$<cr> will find any line that begins with a capital letter and ends with a period and any number of blanks. Try it. Then try something like /"e"<cr> to get back here. The same pattern matching can be used in line mode. For example, to change the first occurrence of "the" on the current line to "that", you can type :s/the/fathead/<cr> and to change all the occurrences, you add the "global" modifier, :s/the/fathead/<cr> LINE MODE COMMANDS The commands that are introduced with the : throw vi into a version of Unix's venerable old line editor, ed. The current version is named ex. Ex and vi are really two modes in one editor. There are many powerful commands in line mode. One that is used often is two substitute one string for every occurrence of another, not just in one line but in the entire file. The :s command above can be modified by putting line numbers in front of the s. To change all "the" into "fathead" in every line of the file, try :1,$s/the/fathead/g You can type u to undo it. The 1,$ in front of the s says "starting at line 1 and continuing to the last line of the file". If you wanted to do the substitution in lines 10 through 20, just use 10,20. In this context, the . means the current line, so if you just want to do the subs in the first through the current line, use 1,. and so on. Another handy line mode command is delete, :d. For example :d delete current line :1,3d delete lines 1 to 3 :1,.d delete first through current line :.,$d delete current through last line :.,/fathead/d delete current through next line that contains the pattern "fathead" On last handy line mode command finds all the lines in the file that match a pattern, and preints them on the screen without modifying the file. Try this command to get all the lines that include the word "fathead". :g/fathead/p MORE EDITING There are other useful commands. The c command lets you change text. For example, if you type cw, a dollar sign will appear at the end of the current word, and you will be put in insert mode. Everything you type will replace the current word when you type <esc>. Likewise, c) will allow you to change the rest of the sentence, c( will change the first part of the sentence, ct, will change everything up to the next comma, and more. The cc command changes the whole line. You can put a small number at the beginning of any of these commands: 3cw changes the next three words, and so on. When characters are deleted from the buffer, they go into an unnamed area from which they can be recalled. Suppose you delete three lines with a 3dd command. Later, a p command will put those three lines immediately after the current line. Try it. A P command puts the lines before the current line. VI MEETS the SHELL The Unix shell offers many useful utilities such as sort, awk, wc, plus dozens of others. These commands can be "integrated" into vi using the ! command (not to be confused with the :! line mode command. Using ! and a cursor motion command, you can send portions of your buffer to a Unix command and get the stdout of the command back in your file. Suppose you have a list of names you've typed Lou Lee Jim Mark Glenn (only many more names) and now you wish they were sorted. Since the lines make up a block of text, you can use the !} command to send them to sort. Just move the cursor to the line containing "Lou" and type !}sort "send block to sort" and the lines will be replaced with Glenn Jim Lee Lou Mark There are five names. Want the names back? Use u to undo. Say you needed to know how many names there were. The wc -l command counts the number of lines in its input, so send the block to wc. Use !}wc -l. The block is removed from the text, sent to wc, and the output of wc replaces the original text. MACROS and ABBREVIATIONS You can define simple macros with the :map command. Suppose we used the block sort above a lot. Then we might use :map !}sort to define ^K to be the sorter. (You cannot type a ^M directly. Use ^V to quote the ^M so that vi will ignore it.) Are you sick and tired of typing National Fuel Gas? Try an abbreviation :abbr nfg national Fuel Gas Now, every time you type the word, nfg, it is replaced magically by National Fuel Gas, WHAT NEXT? Practice makes perfect. Use vi to create files, even if there is a better way to do it. You need the practice so that when you need to do heavy modifications to that TSE input file, you can do them quickly and efficiently. The other thing to do is to read whatever vi manual you can find. Every time I read another one, I am amazed to learn something new and useful, and I've been using vi for about ten years. Good luck! Lee Sailer, for National Fuel Gas July, 1990
rbrown@tron.UUCP (Russ S. Brown) (08/07/90)
>From article <3485@bass6.UUCP>, by yedinak@motcid.UUCP >(Mark A. Yedinak): > > There is a new book out from Hewlett Packard on vi. I have only > > "The Ultimate Guide to the VI and EX Text Editors" by HP After much chasing around with hp I was finally able to get them to admit they had anything to do with this book. I just bought a copy from their Direct Marketing Division. The part number is: Part no. Part Name 97005-90015 MNL, VI/EX TX ED You can order it by calling 1-800-538-8787 in the USA and using your McCard or VISA or whatever. The price was $23.75 USA plus $1.19 USA tax. This book is written in clear language! Enjoy! I don't work for hp, get money from them for this, etc., etc. Russ Brown rbrown@tron.bwi.wec.com -- Russ Brown (301) 765-9930 rbrown%tron.bwi.wec.com from an Internet site -- Russ Brown (301) 765-9930 rbrown%tron.bwi.wec.com from an Internet site rbrown@tron.UUCP from a smart uucp mailer