Without starting a religious war, it's essential to learn the basics of vi for it is ubiquitous on all UNIX variants. Even if you use emacs, it's essential knowledge.
While this argument might have held weight once, I think these factors undermine it:
Emacs used to be considered 'expensive' in terms of disk/memory. These days, it really isn't.
Non-Linux unixes are less and less of a factor these days, and even most of those have some sort of packaging system where installing emacs is a quick operation, rather than a laborious download/compile/install.
Emacs itself has remote editing capabilities with Tramp, via ssh that obviates the need to fire up an editor on the target machine in some cases.
If your job involves sitting down at HPUX/Irix/AIX/whatever machines that haven't been updated since 1998, and don't allow remote access, yes, vi is probably a valuable skill. Otherwise, I think this argument is less important than it once was.
It's still valid. I haven't had to use vi in awhile but there are still a lot of OSes that don't have emacs installed by default. And every so often you'll wind up on a system where EDITOR isn't set and you'll get stuck in vi by accident.
The thing is, though, the subset of vi you have to learn to is relatively small. You need to know how to enter and leave insert mode, how to delete, and how to quit with and without saving. (For a non-vi user, the difference between knowing and not knowing those simple things is significant)
This is generally enough to edit the few configuration files you may need to touch before you install emacs (network, sources.list, sudoers, etc).
So even though the use case is small and shrinking, the amount of "vi skill" you need is pretty low as well. There's really no good excuse to avoid it.
> the subset of vi you have to learn to is relatively small. You need to know how to enter and leave insert mode, how to delete, and how to quit with and without saving. (For a non-vi user, the difference between knowing and not knowing those simple things is significant)
As a self-learner out in the wilderness, I don't know how I could have learned Linux without learning that basic Vi alongside. And that really is all you need to know.
When you're not working on a full linux distro, e.g. hacking a wifi router box or a network assisted storage box, you might not have the luxury of emacs available.
However, it's more likely that you will have some version of Vi. The one I'm thinking of is the Busybox version.
If you use a default server install of debian, ubuntu or centos, it doesn't have emacs installed. The installation media and recovery CDs don't either.
That is enough justification, especially when you're at a single user mode console on a ILO card when the machine won't boot and flames are coming out of everything. Vi is there for you and emacs SSH won't be saving you when the network is not up so you cant apt-get or yum emacs. It's also not the sort of time you want to start having to learn vi.
I know this because I've been there.
It's as important as it always was, much as pen and paper are.
I'm pretty sure that Ubuntu, Debian, and Centos come with nano preinstalled. nano isn't nearly as powerful of an editor as emacs or vi, but it's got most of the basic features you'll need when you're just trying to get the network up and running, for instance. I'm not entirely convinced that, for an emacs user, the added power of vi over nano is worth it in the corner cases where you can't use emacs through SSH, considering how difficult an editor it is to learn.
Indeed. As part of my PhD duties, I've been the lab tutor for the first serious UNIX/systems programming course for the last three years, and I always teach vi:
ESC : q!
Because you never know when some commandline tool is going to drop you into vi (I teach them about the EDITOR variable, but sometimes you ssh somewhere and, you know...), and you need to know how to get out.
True story: the number one cause of issues with source code control systems is a vi session that the students accidentaly opened, managed to flee from with C-z, and didn't realize was still around with an open file holding the subversion lock and preventing them from committing their source code. I'd say I got 5-10 a quarter (~60 students in each quarter's session).
Its worse getting dropped into $USER_FRIENDLY_EDITOR_OF_THE_MOMENT. It's cool that the sys admin or the distro developer loves to use pico, nano, joe whatever, but I just want to make my change and move on.
Our tech staff has a gForge installation that has LDAP configured and all the other goop, but only supports svn. Not managing accounts, password resets, and the inevitable extra map from student id jgordon to login SassySystemsHax0r is a big win.
Since it's their first time using SCC, I already have to deal with "but I just forgot to commit!" for the first two weeks. I'm a little worried that with a DVCS, I'd then also have to deal with "but I committed -- what do you mean I have to push, too? Well, can you grade against the local timestamp?" And that will happen all quarter...
Why? vi and its derivates has their own (weird) usage-convention which you will find in no other software anywhere on the planet. Learning them gives you very few transferable skills.
Any "Unixy" thing you have around these days will have more resources than most computes did in the mid 90s, and the need for a "lightweight" editor like vi is much, much smaller now than it was back then. Even my Buffalo router has nano.
For most Linux distros you install, you typically have nano, pico, joe, jedit or emacs or lots of other editors which (apart from emacs which is its own universe) largely follows the same conventions and at large gives transferable skills. These are IMO much more useful to know.
Why should I bother learning an archaic, non-standard editor from an era when "line-editors" were considered bloated? Why should it even be considered "relevant" today? Even more so, why should it be considered "essential"?
I really don't agree and I really don't see why vi-users insist everyone need to learn their favourite editor.
"Why? vi and its derivates has their own (weird) usage-convention which you will find in no other software anywhere on the planet. Learning them gives you very few transferable skills."
Arrgghhh!
man readline, and search (/) for inputrc.
ANY app that uses readline can be set to use vi OR emacs keystrokes and history, by setting an entry in .inputrc. If you use either editor regularly this will set your command line skills in lots of software all over the planet to warp speed.
If you write python command line programs, try "import readline."
And even more, there is rlwrap (i.e. readline wrap) command line utility that wrangles the badly behaved tools and allows you to use VI editing mode with almost anything (like cat command etc).
While I'm still not going to bother with vi, I do have to admit this is probably just another one of those not-widely-known things about "Unix" which deserves some attention. God knows I didn't know about it.
Other cute things I have discovered lately: You can actually click in ncurses dialogs running in your terminal, even over SSH, if you run a proper terminal. Coming from a PuTTYish background, that is definitely not obvious ;)
And, if you've set -o vi in bash (etc?), when you're editing a command line and need more than just the limited set of vi commands that make sense on a command line, do this:
esc v
esc gets you out of input mode, and v takes the current command line that you're editing and opens a full vi/vim session initialized with the command line. After you're done editing it, :wq quits vi and executes the command. If you change your mind, delete everything in the buffer and then :wq
This is handy if you're editing a biggish command, particularly one from recent history like a loop or anything with a block.
FTA: "If you learn to use Emacs, you will automatically learn the hotkeys and keybindings in hundreds of applications in Unix."
His point here is not to learn Emacs because it's a good editor, but because the keystrokes transfer to "hundreds of applications in Unix."
Which is true enough. In the (bash etc) shell you can change that to vi keystrokes with set -o vi, and you can change the behavior of those hundreds of applications (like mysql, e.g) by having a .inputrc file, but by default, lots of those apps use emacs keystrokes.
Use whatever editor you want, for whatever reason you want. His suggestion is worth considering, for the reason he states.
I'd especially like to point out that vi is the de facto editor in embedded Linux installs, since it comes with busybox. Unless you want to constantly shuffle files around between your machine and the embedded one, you just have to learn vi.
ed/ex is well worth learning. The other vi commands are less so, unless you prefer to use vim as your main editor.
If you are a vim power user, finding yourself using traditional BSD vi is likely to be an unpleasant experience, making the vim is great because vi is installed everywhere weak as an argument.
Let's look at a typical novice's session with the mighty ed:
golem$ ed
?
help
?
?
?
quit
?
exit
?
bye
?
hello?
?
eat flaming death
?
^C
?
^C
?
^D
?
---
Note the consistent user interface and error reportage. Ed is generous enough to flag errors, yet prudent enough not to overwhelm the novice with verbosity.
Not really. VIM has vi as subset, and plain vanilla vi is still quite powerful text editor. It doesn't have a lot of bells and whistles, and I would not choose to use it as the primary editor for all tasks, but if I'm on a system where I have to edit something using plain vi, I won't have a hard time doing it and doing it fast.
No, because I know I'm using plain vi :D. I spent a good deal of my life working with plain vi, and the company I work for makes a port of POSIX APIs, UNIX shells and all typical command line utilities for Windows, which includes vanilla vi. So I'm used to it.
I use VIM with only a few extensions (taglist, command-t and snipMate). I also use ctags and cscope, but support for those is built into vim. I really try not to get too dependent on extensions. They are more like convenience rather than something you don't know how to do without. Command+T for example is useful, but you still should know how to get to your files from the command line.
While I find myself using Emacs more that Vi/Vim these days, I still find Vi key-bindings useful in the less(1) pager, which I use extensively.
I've just discovered that less responds to Emacs movements, but for searching text I rely on the vi slash. Secondly, when navigating multiple files in less, the vi/vim "next/prev file/buffer" commands (n/p) apply.
Ed really is worth learning, if only the basics. No matter where you end up, ed should be around. Even if you find yourself logged on to a Plan 9 box via telnet or something, ed will be there. Plus, the commands transfer to vi, and the ed command language is essentially the same as the sed command language! (and the Sam command language, used in the sam and acme editors, but those aren't as popular :)
I knew a guy who actually did this - he worked for a company that maintained process control systems for "serious" customers (steel mills, nuclear power stations). One steel plant had some ancient mainframe controlling things and it originally booted from paper tape that had long since worn out in the eons since it was installed and been replaced with a sturdy leather belt.
He had to patch the boot code - so hence had to resort to a handdrill to drill some new holes in the leather belt.
If you want to use vim for development, use vim. But "it's the default" is simply an untrue statement. Vim (-full) is no more "the default" than Emacs. Both need to be manually installed on nearly every operating system.
Please substitute "vi" in my comments for "vi or appropriate compatible substitute" such as nvi, vim, elvis etc. They all work the same with the usual subset of commands :)