Site Administration Page 2 - Vi 201 |
See Also: The last time we met, I told you that vi operates in either one of two modes - "command mode" and "insert mode". Well, I lied. Don't look so horrified - I hate to burst your bubble, but people lie all the time. And just so you know - Santa Claus doesn't exist, and the tooth fairy decided to get out of the business a few years ago; she's now in Las Vegas earning millions as a showgirl... Anyway, getting back to vi - the editor also comes with a very powerful "visual mode", which allows you to select blocks of text and perform actions - cutting, copying, deleting - on them, in a manner similar to Windows-based editors like Microsoft Word. Entering visual mode is simplicity itself - simply hit while in command mode. Vi will display a visual notification of the mode change at the bottom left corner of your screen. Now try using the various motion keys to move around - you'll notice that instead of moving you around the document, those keys now control a selection block which can be used to highlight sections of the text. In addition to visual mode, there's also a "visual line" mode, which allows you to perform line-by-line selection and is activated by hitting and a "visual block" mode, which allows you to select vertical, rather than horizontal, blocks of text - hit to activate this mode. In all these different visual modes, the usual motion keys can be used to control the size of the selection block. Now that you've got your text selected, it's time to do something with it - and vi comes with some built-in actions that allow you to interact with your selection. For example, type to delete your entire selection, or to copy it. You can then paste it by moving to the appropriate point in your document and hitting The "change" command, activated in visual mode by typing will delete the selected block and enter insert mode at the first character position of the deleted block. If you're a programmer, and can be used to indent blocks of code left and right, respectively. And can be used to switch the case of the selected text, from upper-case to lower-case and vice-versa. A couple of other interesting commands in visual mode - type to move the cursor between the upper left corner and lower right corner of your selection block, or to repeat the previous selection. To exit visual mode, simply tap the key, and you'll be returned to command mode. As you'll see after you play with it for a while, visual mode is extremely powerful. It comes in particularly handy when you're dealing with large text files, and need to transpose sections of text from one place to another - instead of counting the number of lines to be copied, and then doing a or a you can simply select the lines of text with the motion keys, and use the operators above to transfer them to their new home. With power like this, who needs Santa Claus? This article copyright Melonfire 2000. All rights reserved.
blog comments powered by Disqus |