Yehuda Katz is a member of the Ruby on Rails core team, and lead developer of the Merb project. He is a member of the jQuery Core Team, and a core contributor to DataMapper. He contributes to many open source projects, like Rubinius and Johnson, and works on some he created himself, like Thor.

@gmcintire Passenger may be setting GEM_HOME differently -- can you print out ENV["GEM_HOME"] in passenger?

Everyone Who Tried to Convince Me to use Vim was Wrong

A couple weeks ago, I took the plunge and switched to vim (MacVIM, to be precise). It wasn’t the first time I tried to make the switch, and I had pretty much written it off entirely.

Why? Because the past few times I tried switching to vim, I took the advice of a master vim user, and quickly sunk into the quicksand of trying to learn a new tool. In every prior attempt, I gave vim a few days before I gave up. And every time, I managed to get virtually no work done the entire time, spending about 90 percent of my day fighting with my editor (a more charitable way to put it would be “learning my editor”).

Invariably, the master vim users that were helping me make the switch would encourage me to stick it out. “If you just give it a few weeks, you’ll never want to switch back.”

The trouble was, I had work to do. I could only switch editors if the new editor did not significantly impede on my day-to-day work. I can already hear the responses: “That’s simply impossible. It’s a new editor designed for advanced users. You’ll just have to put up with the pain until you get used to it.”

Here’s the thing, though: I didn’t really have to put up with a huge amount of pain when switching to Textmate for the first time. In fact, it was downright pleasant.

The last few times someone tried to get me to switch to vim, I issued them a simple challenge. Can you tell me a way to switch that will not significantly reduce my productivity for the first few weeks. It wasn’t a challenge that was intended to fully shut down discussion. When I really thought about it, Textmate wasn’t doing all that much for me. It was a glorified Notepad which had working syntax highlighting and understand where to put the cursor when I hit enter (most of the time).

I don’t actually use “snippets” all that often, or all that many “commands”. I don’t mind the extensibility of Textmate, but I’m not a hardcore Textmate hacker myself, meaning that I’m ok with any editor that has the same level of extensibility that Textmate has (namely, all of them).

Despite what I considered a relatively reasonable request, my challenge was met with disdain and even anger by most of the people I talked to. “If you feel that way, Vim probably isn’t for you.” “You’re learning a new EDITOR for God’s sakes. Of COURSE there’s going to be a learning curve.”

I had written off the entire sorry affair.

A few weeks ago, Carl told me that he was playing with Vim. His explanation was that he had seen a number of people be really productive with it, and he was curious. Carl is definitely willing to put up with more pain to learn something new than I am, so I issued the same challenge to him.

Perhaps because he wasn’t steeped in hardcore vim hacker lore, he didn’t angrily dismiss the entire premise of my question. Thinking about it a bit more, I realized that most of the people who had tried to get me into vim had suggested that I dive in head first. “First thing: turn off the arrow keys.” “Don’t use the mouse. Force yourself to use the keyboard.”

Carl convinced me to use vim for the first couple of days pretty much exactly as I use Texmate (with the exception of having to switch between normal and insert modes). I installed NERDTree on MacVIM, grabbed the most common vim “packages”, and was off to the races. (I should note that I installed topfunky’s PeepOpen, which definitely helped with a very common workflow that I find it hard to live without).

For the first day, I clunked around by using my mouse’s scroll wheel, clicking and highlighting things, and spending most of my time in insert mode. It was slightly less productive than Textmate, but mostly in the range of what I’d expect switching to a new tool. In short, while I felt a bit out of sorts, I was able to get plenty of work done that first day.

As the days went on, I learned a few commands here and there. The first big one for me was ci as in ci " (it means: replace what’s inside the next set of " and go into insert mode). This singlehandedly made up for most of the productivity losses I was feeling from learning a new tool. Throw in o, O, A, :N and /search and I was already quite a bit more productive than I had been in Textmate.

Sure, I’m still plodding around in some cases, but only a handful of days later, using Textmate for anything feels clunky (most commonly, I try to use o or O to insert a new line above or below the one I’m currently on).

I was able to get here because I used my mouse wheel and button, arrow keys, apple-f to find text, apple-s to save files, and a whole slew of other common idioms, instead of grinding to a halt and trying to switch all of my practices at once.

To those who would say “that’s obvious; of course you learn vim incrementally”, I would simply say that having spoken to a number of vim users in the past, I never got that advice. Instead, I got a lot of advice about turning off my arrow keys, disallowing the use of the mouse, and learning the (MORE EFFICIENT!!!) vim ways to do everything, all at once. People just couldn’t stomach the idea of me continuing to use an outmoded practice (like apple-f) when vim had much better tools available just a (huge volume of) memorization away.

To those who are considering using vim, my recommendation is to use MacVIM, NERDTree, PeepOpen (or command-t), and use the mouse, arrow keys, and familiar OSX’isms all you want. Very quickly, it will become obvious that there’s a better way to do all kinds of things, and you can pile on the newly found efficiency once you’ve successfully made the switch without losing the ability to do work in the short-run.

Share and Enjoy:
  • Digg
  • Reddit
  • HackerNews
  • Twitter

169 Responses to “Everyone Who Tried to Convince Me to use Vim was Wrong”

Interesting post, though I never been as productive with VIM as I’m with RubyMine.

VIM has no visual debugger, test runner integration (cucumber, rspec, name it), version control integration, usage search, refactorings?

And still RubyMine is _very_ keyboard focused. For TextMate and VIM addicts it has corresponding keyboard layouts.

Sorry for ads, I’m working for the company which develops RubyMine (JetBrains), but still, RubyMine _is_ very useful.

Thanks for listening,
KIR

Congratulations on your attitude and I hope the investment in time pays off quickly!

And now I can brag: “The coolest developers on the planet use Ruby, Rails and Vim, for example …”

Seriously though, you have inspired me to take a different approach to learning Emacs/Viper – last time I tried, I was so frustrated, I removed it from my system.

For those interested, I couldn’t get Ruby syntax highlighting and electric mode to work and Viper mode was in reality too different to cope with.

A warning! Vi keystrokes are contagious and you may want them everywhere: my current setup wouldn’t allow me to otherwise to use irb, read/write email, use the command line or even browse the web!

This is funny, because I did exactly the opposite.

I cut my teeth on vi, then moved to vim- gratefully, because it offered effective visual text selection features. But I chafed at the frustration of sorting out which files I had open already and where. Also it encouraged me to think in terms of 80-column lines, and god forbid anything be larger, which just didn’t fly in an office full of kids who grew up in the post-text-mode era.

My coworkers use TextMate, so I gave that a try. It worked well enough for me that I wound up aliasing the ‘vi’ command to TextMate’s command line ‘mate’ front end. That’s right- now I *can’t* use vi (well, not without a special and conscious effort).

I found that was the only way to get out of the vi habit. I haven’t regretted it. In particular, the ‘script’ snippet (type script, press tab, presto an XHTML compliant script tag with the usual attributes and blah and blah) is a big win for me.

TextMate does have its warts- the built-in multiple-file search is just awful- but I never searched multiple files in vim anyway. That’s what find . | xargs grep is for!

I was a long-time Emacs user, switched to TextMate when I got a Mac.

I still constantly use Emacs-style keybindings (which work in most Mac apps), and I’m afraid that I’ll be frustrated if Vim doesn’t support them. Is there a configuration for Vim that provides support for basic Emacs-style motion and editing?

Just take the BS from the vim hackers, replace “vim” with “MAC”, and voila. Now perhaps both sides can see how they look to everyone else on the damn planet.

If there was any reason not to use vim, it would be the comments from the assholes in here. Myself not excluded.

Actually my difficult with vim is with windows/buffers/(and tab). How you guys make use of them? The windows never work for me, either on big or small screen. After a while with hsplit, vsplit I always end up in a awkward window layout. The ZoomIn plugin does help (allow to maximize/restore window), but then it doesn’t bring any benefit of windows at all. So I end up working in full screen mode. In order to switch to another file, I have to go to the buffer list first (and to go to buffer list I need a few key strokes).

So how do those windows/buffers/tabs works for you?

@Kirill

Why do you need such “integration?”

I personally use GNU screen to allow me to have debugger sessions (though I don’t debug ruby the gdb way), my text editor, a shell or two, and the rails server all running.. each can take over the terminal with just another simple keybinding.

Integration is overrated for those who know what they’re doing.

Nobody mentioned viplugin (viplugin.com) for Eclipse. You get the best of both worlds….

Yehuda, can you please share your ~/.vimrc ?

Couple of tips for working with Ruby in vim: http://jetpackweb.com/blog/2010/02/15/vim-tips-for-ruby/

Yahuda,
You may want to try dd (D), cc (C) etc. I was pleasantly surprised when I tried C and cc commands. C deletes to the end of line and puts you in the insert mode at the current cursor position whereas cc will delete the current line and position your cursor where the start of the line should be. I am not sure if you use “ack”, but if you install it straight as a perl script (not using Macports) and put in your bin dir, you will be amazed at how powerful your search (find and grep) can be. Nice thing is, it is so easy to customize this perl script for your requirements for ANY kind of searches. I keep it out of VIM as a plugin and as a stand-alone utility. Even hard-core Windows/Java programmers like it in our shop.
Bharat

I’m not a MAC user but it’s definitely how I came to use (G)Vim!

This might seem right out of left field, but there is a collection of vimscripts under the name “cream” which is essentially a vim-lite. I have no idea if they have a mac client but it’s a set of vimscripts so it shouldn’t be hard to place into MacVim.

It’s very friendly to walk into, and uses a lot of gVim attributes to get things done.

Good post, Yehuda – If you’ve been using a powerful editor for a few years, especially one as rich as Vim, it’s easy to forget what it was like when first picking it up. This is a good reminder.

Your post prompted me to share what worked for me while I was initially learning Vim: http://www.thegarvin.com/2010/08/04/tips-for-learning-vim.html

Thanks for the inspiration.

Jim Garvin/@coderifous

@Tom

For better (IMHO) Vim emulation in Eclipse there’s the vrapper plugin:
http://vrapper.sourceforge.net

It’s open-source and it’s still actively developed.

Hi Yehuda!

I’m thrilled to hear you’ve inched your way onto the VIM train!

@Yehuda — I think you maybe did this intentionally, but the title of this blog post really seems to imply that the subject of this post is going to be about “Why you *shouldn’t* use vim”. Seems like a more accurate title would be something like “Everyone who told me how to learn VIM was wrong”… something like that….

@Chuong (and also Yehuda):
For opening files, I’m a fan of FuzzyFinder, which I’ve aliased to `command-t` and also `,ff` (“fuzzyfinder”). For tabs… I personally never open files from the buffer, I open a new tab (`:tabedit` is the command which I have aliased to `,te`), then open my file with `,ff`, and switch between tabs with the universal OSX `command-shift-[` and `command-shift-]`

I’ve heard that PeepOpen has more features, but also more bugs than FuzzyFinder; ultimately I’m a fan of “free” so FuzzyFinder FTW!

@Yehuda –
The reason that people recommend diving in instead of inching in, is that the real gains you get from VIM are from the muscle memory you develop for these efficient editing commands, so that the barrier from thinking about code to having that code written is very low — for me, it almost feels like I don’t even write code, I just think about it and it appears on my screen. Like magic. But if you “inch in” (so to speak), you will often continue to use your old (inefficient) commands and never bother learning the efficient VIM commands. For a concrete example, if you continue to move your hand down to the arrow keys to navigate, then how will you build that muscle memory for h,j,k & l for navigation?

The point being that when you know a “vim” way to do something, you should force yourself to use it, even if it feels strange at first, because you will get used to it very quickly and then it will be second nature. Whether you do that one command at a time, or 5 commands at a time, or all commands at a time, doesn’t really matter. It kinda ends up being like the difference between a rolling deploy vs. deploy to all appservers at once. In one case you have minor disruptions over an extended period of time, in the other case you have an extreme disruption (downtime) for a short period of time.

For me, I wasn’t really attached to any editor when I started using VIM (technically, I also use Macvim). When I started at this office, I had been using Eclipse for about 6 months and didn’t love it, I tried Textmate for about a week and didn’t love it, then I watched my new coworker using Macvim and was amazed at how he appeared to have magical powers. He told me to spend 30 minutes going through vimtutor, which I did on BART on the way home that day, then 2 days later, after using only Macvim, I felt 200% more efficient/productive and happy than I had been with any other text editor. I bootstrapped with his dotfiles (http://github.com/scudco/dotfiles). They’re an awesome starting point.

Now pairing with my poor colleagues who still cling to the tree of Textmate, afraid to jump into the lovely sea of vim (does that metaphor work?) tends to cause mental anguish for me. The inefficiency really makes my brain hurt by the end of the day.

-Steve

Ruby community is extremely fashion driven, current fashion is vim so everybody has to learn it. :) I am glad you have to suffer as well.

I use it fairly productively, I don’t think any developer will become better because of it, nor I think other editors prevent me or anyone from writing good code, but then any developer who is good should be able to use tools available, so using vim at the moment seems to be the way to talk to others, hence me using it again.

Thanks for sharing your vim-conversion story! Had I not learned vim from Tim Pope, I probably would have a similar story to yours. Also, pairing with other vim users was tremendously helpful – a rising tide floats all ships and all that.

Thanks! I’ve had programmers tell me how to switch, but they never seemed to understand that I’m a grad student. Spending three weeks doing nothing but learning vim is actually worse than doing nothing at all for three weeks. It’s an excellent way to get your PI, postdocs, grad students, faculty, well, pretty much everybody PO-ed at you. This way I can actually learn vim at my own pace. The only thing I can think of is recommending people learn to navigate without arrow keys. It’s just 6 keys (4 nav keys + esc + i), and that gets you started!

Leave a Reply