Site Administration Page 3 - Vi 101 |
Starting a vi session is ridiculously simple; type at your UNIX shell prompt, followed by a carriage return, and vi will pop open an empty file for you to begin work. Alternatively, you could specify the file to open on the command line itself, like this: Don't worry about the ~ signs in the editor - they're simply visual indicators of the bottom of your file, and don't actually appear in your document. The first - and most confusing thing - about vi is the various different modes the editor can operate in. For our purposes, I'll split them into two broad categories: "insert mode", and "command mode". "Insert mode" is where you'll be spending most of your time - it allows you to add, or insert, text into your document. "Command mode," on the other hand, lets you move around the document, delete or replace blocks of text, and access useful vi functions like buffers and ranges. When vi first starts up, it's usually in command mode. To enter insert mode, type vi will display a visual notification of the mode change in the bottom left corner. You can now enter text into the document in the normal manner; when you're done, hit to return to command mode. To begin inserting text on a new line, try to enter insert mode with the cursor already positioned on the next line, or to enter it with the cursor on the previous line. In addition to inserting text, vi also allows you to overwrite existing text - this is known as "replace mode", and can be entered by typing from command mode. Everything you type will now "write over" existing text. If your intention was to replace a single character - for example, correcting a spelling error - use to replace only a single character; the editor will automatically return you to command mode after the character has been replaced. Obviously, at some point, you're going to need to save your work. In vi, this is accomplished via the "write" command, abbreviated to To quit, use the handy "quit" command, known to family and friends as vi also lets you combine frequently-used commands together - to really impress the pretty girls, not to mention add a few points to your geek quotient, try for powerful save-and-exit functionality. Alternatively, if you've decided to bury whatever you've just written, try which exits vi without saving any changes to the file being edited. Obviously, all these "colon" commands need to be executed in command mode - attempting them while in insert mode will result in them appearing as part of your document, and no professor likes to receive assignments interspersed with :wqs and :q!s. Well, actually, some of them do - but that's mostly the younger crowd, and what can you expect from them? Those punks actually think rock 'n' roll is dead... This article copyright Melonfire 2000. All rights reserved.
blog comments powered by Disqus |