vi - the
"visual editor" Remember: beat on the Escape key a lot download or view a vi cheat sheet (in pdf file format) |
![]()
|
|||
The first thing to
tell you about the vi editor is, you won't be impressed. The second
thing is that we're not here to impress you. Then, there are a bunch of
other things to say about it.
You Won't be Impressed Editors, like everything else in computers, have evolved in an increasingly slick, graphical, and intuitive direction for such a long time that everybody who uses computers in a desktop/client role has gotten used to their ease-of-use standard. By contrast vi, on first encounter, feels like a dinosaur. And it is ancient (20 years, the plastocene). vi's character-based, not graphical. It sometimes does and sometimes doesn't exhibit the same behavior in response to the same keystrokes. When staring at its inscrutable prompt there is no context-sensitive help to call on. You won't be impressed. Because you will be using the editor yardstick you've become accustomed to in your role as the web-surfing computer consumer that, most of the time, you are. We're Not Here to Impress You Not now. You're in a Unix class. Unix has GUI interfaces (a big choice of them) but is natively character-based. If you want to use Unix through a GUI exclusively you can. But if you want to access its fullest power and capability, and put it to use where its great comparative advantage lies (as a server), that's not what you want to do. Everything in Unix is regulated through the editing of configuration files. Text files. Programs read them and follow the "instructions" therein. Making Unix do what you want amounts to crafting the right text in those (many) files. To do that you don't have to learn vi, necessarily. There are other character based text editors. But you do have to be able to edit text files. Necessarily. Now that I've emphasized the case against, what are the reasons FOR learning vi? First, it's universal. There isn't a version, brand, or dialect of Unix where you won't find it. Second, its keystroke command set is found all over the place within other commands and utilities, which have adopted it. For example, when you use the "man" command to view the documentation for a command, if you want to search for a word or expression you use the same : / (colon, then slash) key sequence as you would within vi. The "less" command is another example. So you need to learn how vi works anyway. Third, vi occupies a different space than do easy-to-use GUI editors and serves the needs of that space (power) very well. Unix has good GUI editors too. But that's not what vi is about. So, if someday you'd like to be an at-ease, capable, skills-transferable inhabitant of the Unix world, you better know vi. Here's another author's statement of the case: Other Things to Say About vi There's a lot of literature so I won't say much. But the most important initial ice-breaker is to get an understanding of the 3 "modes" in vi and the keys you need to know to transition among them.
The confusing thing about vi is not knowing which mode you're in, because keystroke behavior depends on mode ("I wonder what's gonna happen when I press the x key this time?"). The thing to note above is that the same key puts you into command mode no matter what mode you start from. It's the Esc key. So my cardinal rule when confused, is to repeatedly bang on the Escape key to get myself into a known state, namely command mode. From there I know how to get wherever I need to be. After you get to command mode further Esc keystrokes usually cause a "beep." Extra keystrokes are harmless so feel free to bang away as much as necessary. Please read the slightly more formal exposition of this idea found in the "Linux Installation and Getting Started" guide's section where you should search for "3.13.1" to find the section of interest (use the search feature found on your browser's Edit menu). Read the entire 3.13 section of that document, doing the exercises offered as practice. You may also try the interactive practice tool "vimtutor" installed on many linux systems.
|