Many people rave about the vi editor (and on the occasions that I have had to ssh into a remote host, it is often necessary to use - now where did I put that cheat sheet), but how much of this is snobbery? Can vi do anything that a typical graphical editor like gEdit, TextEdit, Notepad or the editor that comes with Eclipse can’t do?
With vi, your hands practically never need to leave the home row. Touch-typists absolutely love that. Further, vim, the modern version of vi, has a ton of plugins that help it do just about anything you could possibly want in relation to editing text and writing software; other editors are a lot more limited.
Finally, of course, Eclipse is simply slow and Notepad is a bad joke.
Compared to modern editors, vi is very lacking. It was far and away the best at the time of its introduction into the UNIX world, and deserved a lot of praise at that point. Many programmers spent tens of thousands of hours working within the vi editor and it became the standard by which all others were judged. Today it’s antiquated and really only important as a editor of last resort because it was standardized around for so long and is highly available and reliable. If there are other editors you like better, go ahead and use them and don’t worry about anything else.
A parallel situation existed in the world of amateur radio where you couldn’t get a broadcasting license without taking a high speed Morse code test. Morse code was the standard of last resort for radio communication for so many years that even when it was hopelessly antiquated by both better emergency communication matters and advances such as full voice transmission, it still was kept around because of it’s historical importance and people’s sentimental attachment to it. In fact it was only dropped from the official requirements for amateur radio operators a few years ago (2007).
If vi follows anything like the pattern of Morse code, we could still see it on systems for another forty or fifty years. Hang on to that quick reference sheet.
Don’t forget about emacs. Both vi and emacs are extremely powerful once you learn how to use them (and there is quite the debate about which is better). They have a steep learning curve. The idea is to make editing more efficient. vi does this primarily through the use of input modes. In one mode you are typing your content, while in another mode each letter on the keyboard is used for various editing functions. For example, in edit mode you might type ‘wD’ to move one word forward and then delete to the end of the line. This is much faster than hitting the “->” key or using the mouse to select a range and then hit ‘delete’, like you might do in Notepad or whatever. And this is just the tip of the iceberg. All off these little techniques save time, and it adds up. Emacs is a different type of editor which makes use of customizability and keyboard shortcuts. So, for example, in emacs, you could do the same thing as above by mapping some things like ‘ctrl-x’ to various functions like deleting to the end of a line. In emacs you have to hit a few more keys, but you don’t have to constantly switch between input and editing modes. If you are a programmer, you will probably love vi or emacs. You can do lots of fancy things using what are called ‘regular expressions’ which allow you do do extraordinarily complicated search-and-replace using pattern-matching. If you are just writing reports or something then it is not likely to be as useful.
Per usual for open source tools, the answer is “a bunch of geeks got used to it back in the 80s, and they still use it because they hate learning new things.” They’ll come up with various excuses for this, but that’s what it amounts to.
It’s the one editor that’s guaranteed to be on any Unix system. If you touch Unix systems you need to know vi. Keep the O’Reilly book at hand.
Yes, vi is antiquated and sucks, but it’s there. In its defense, I have yet to see a GUI-based editor that has the global search and replace with regular expression features of vi. There’s no reason those features couldn’t be in a GUI-based editor, they just aren’t.
vi is great, in that it has all sorts of complicated advanced features, available with only a few keystrokes. Unfortunately, one of those complicated advanced features is typing text. But hey, how often do you need to do that in a text editor, anyway?
Personally, I prefer pico. It’s nearly as ubiquitous as vi, just as compatible with a terminal window, and much easier to use.
Let’s break up editors into two groups: GUI and non-GUI editors. GUI editors have a menu bar where you access tasks and require extensive use of the mouse. Non-GUI editors use keyboard commands to perform tasks and do not rely on the menu bar or mouse. Some non-GUI editors may have menu bar and mouse support, but that is to provide an alternative access method to the keyboard commands.
The advantage to a non-GUI editor, of which vi is one, is that the editor can fade away. Once the keyboard commands become well learned and automatic, the operator no longer feels like there is an editor between him and his text. The text just flows out of his hands in the format he wants. In a GUI editor, every time you use the menu or mouse, you’re reminded that you are interacting with an editor.
An analogy might be driving a car. Likely you don’t have to think about how to drive. You just get in and travel to your destination. You turn the wheel, use the pedals, use the blinkers, etc. without thinking about any of it. That’s what vi becomes like. The text just comes out without you having to think about how to make it happen.
The strength of vi specifically is that it is available on every Unix platform out of the box. Remember, many Unix boxes don’t have a graphical terminal. So to have a powerful, familiar editor available everywhere is very useful.
I think you’re making a distinction where none exists. To go back to the Visual Studio example, while it is true that VS probably has (slightly) fewer keyboard shortcuts than VI, it’s still eminently usable without ever touching a menu.
And again, even going all the way into customer friendliness, even Word is entirely usable without ever touching the mouse. (Well, not the drawing tools I guess. But most of it.)
But since you don’t need to touch the mouse to use Visual Studio (once you know it), there’s absolutely no difference here. The only reason you’re looking at the menu in Visual Studio is that you don’t know it as well as VI. Not because VI is somehow superior.
It all comes back to learning curves:
A lot of geeks love VI because they spent the 10 years learning it, and they refuse to learn anything else. I wager that if you’d spent those 10 years learning Visual Studio instead, you’d be making the entirely opposite argument right now.
Yes, but shouldn’t your text editor of last resort be at least friendly enough so that the uninitiated can figure out how to exit it without killing the process? I still say it’s bad design in the *nix world to use VI as a text editor of last resort-- PICO, as mentioned above, would be a much better choice. (But of course that change will never happen, because *nix developers are creatures of habit, and they all already know VI…)
Not to the extent of vi. We aren’t just talking simple search and replace here, but stuff like "on all lines ending with foo, swap the parts of the line separated by the pipe sign:
:g/foo$/s/^(.)|(.)$/\2|\1/
Frankly, I don’t use vi often, but when I do, it’s usually because I find it easier for ad-hoc massive file massaging than doing a bunch of throwaway shell script.
I would argue that if you’re doing operations like that, you’re using the wrong tool entirely. For example, wouldn’t a spreadsheet be better for tabular data?
Following up your second paragraph, for me that’s themost important thing abotu vi, it works in just about any terminal you throw at it. Maybe people that have grown up just with Windows or Macs don’t know about it, but there are all sorts of different terminal modes for using connections between machines (via the likes of telnet and ssh). Back in the day - and still very much so in the corporate world - that was the way to do networking and vi was the one editor you absolutely definitely knew that not only would be there but also would work properly. Other editors might screw up how they look, keyboard shortcuts might fail or whatnot. But vi you could trust.
I still use vi now and again, but I usually end up with nano, a copy of the pico that Chronos mentioned. But now and again it doesn’t work. Also, on certain Linuxes, vi is the default editor when editing crontab when using “crontab -e” (crontab is a method of scheduling jobs) and also for editing certain important files in a secure way so they don’t get corrupted (visudo, for example, is one for the editing of the sudoers file, which controls who can and cannot access the system, as well as controlling certain execution rights and whatnot).
I’m having trouble coming up with a population of humans which love learning new things more than geeks. Perhaps your experience with geeks has been different? It’s more the businesspeople and marketing people who have kept vi around for so long because it was adapted into the SVR4 standard, so all SVR4 UNIX platforms include it.
If you want to see what UNIX might look like if it were in the hands of the geeks instead of committees of business people trying to make it a commercial product, look at Linux. Dozens of editors in pretty much every distribution.