Yehuda Katz is a member of the Ember.js, Ruby on Rails and jQuery Core Teams; his 9-to-5 home is at the startup he founded, Tilde Inc.. There he works on Skylight, the smart profiler for Rails, and does Ember.js consulting. He is best known for his open source work, which also includes Thor and Handlebars. He travels the world doing open source evangelism and web standards work.

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.

237 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!

The recently released E Text Editor 2 looks like it would be right up your street as it is basically TextMate with a nascent Vi-like command mode:

http://e-texteditor.com/blog/2010/beyond-vi

Shame it’s only on Windows for now. It *can* compile on Linux, but currently needs a lot of TLC there before it could be considered usable. It’s on github if anyone is interested: http://github.com/etexteditor/e/

Buffers?

add the following to your .vimrc file have better access to your buffers

” map Ctrl Shift B to open the buffer list.
:map ^B :buffers^M

enter the ^B and ^i by typing and

now switch files with two keypresses
:-)

Now with one more month of practise, may I suggest you the vimcasts.org screencasts? (1 new episode per week; currently stalled as Drew Neil, the site owner, is in vacation.)
I’m using vim for almost 15 years now (but cannot be considerer as a hardcore user), and found new tips & tricks in almost all of the episodes.

For those that have problems with buffers, windows or tabs, there’s a few episodes about those topics.

@David M.:

If you are an emacs user, do not try to use vim with emacs bindings, just use emacs.
GNU Emacs is available for almost all platforms, so you just have to install it and get your feelings back.

C-x-c

This is a great article, Yehuda. I’ve tried to switch to Vim many times over the years, and yours was the approach that finally worked for me. It also made me think about *why* nobody else is saying this, why the Vim dogma is so pervasive:

http://code.alexreisner.com/articles/vim-heresy.html

I’ve used vi for years but I had to ditch it because of the copy/paste functionality I’ve learned to expect from Windows and most every other editor – Control C/Control V/Arrow keys with/without shift(and alt) to cut/paste things.

I understand some of this can be emulated but I never was able to figure out the arrow key aspect with shift (and alt). Is this somehow possible? I’d love to use vi again for coding.

@Kirill: as much as I think Rubymine is a good product, you’re just spreading FUD. Vim has integrated ruby debugging (http://github.com/astashov/vim-ruby-debugger), test runner integration (http://www.vim.org/scripts/script.php?script_id=2286 among others), version control integration (http://github.com/tpope/vim-fugitive and http://www.vim.org/scripts/script.php?script_id=90), and many other features beside, in plugins. It has all these things, costs nothing, takes no time at all to start up, allows me to keep my config in plain text and under version control, and doesn’t leak memory on big projects.

The fact that Rubymine has a keyboard shortcut profile for Vim fans doesn’t make it anything like Vim.

thanks, while I’m not interested so much in vim or any mac code editor, this was an interesting study of the process of learning a new user interface. And also a funny look at your diva friends LOL.

Thanks, this article convinced me to take the plunge — I was definitely trying to power-use VIM out of the gate, and like you, couldn’t cope with the huge productivity loss. Think I’ll try your approach for a week and see if I make any headway…

@Mark – https://github.com/carlhuda/janus

Very good article.

I agree that most vim power users tend to focus too much on the complete switch instead of the incremental stages in between notepad-style editing and hardcore, dark-ages vi. I think this is due to overcompensation for judging vim too harshly on the ‘in between’ stages as well as a lack of those stages early on.

Things such as :behave mswin and :source $VIMRUNTIME/mswin.vim are niceties that haven’t been around all that long compared to many of the vim power users out there. Further, there are rough corners here and there; for example, yank and put don’t interact directly with the system clipboard.

Lastly, I think that everyone ends up focusing on the ‘most extreme’ differences between their editor and everyone else’s. Using hjkl instead of the arrow keys is extreme, though not (eventually) without merit.

I may end up writing up a guide for switching to vim for people who still need to get their day job done.

Congrats,

I’m finally conquering the mighty VIM myself, after years of nano or textmate. It’s a struggle some days trying to flip into that mindset but it’s so rewarding when it works right.

I’m also trying EMACS, not sure which one to use predominantly but will work that out later.

You just spoke my mind !!
=> I am just right now starting to use VIM, Switchin gvom Textmate and Notepad++.
I tried it so many times and so many times I failed.
Thanks for this great post!

I like the incremental method and I think it served me well while learning.

vi confused the hell out of me when I first encountered it. It didn’t help that I was learning it along with trying to fight my first server without the common sense to just install nano.

Frustration with Eclipse taking so long to do anything lead me to decide to attempt learning vim. I took my hit in productivity but took the approach of learning the bare minimum: how to enter/leave insert mode and how to save and quit

Next came learning to fix issues as I ran into them such as how to search and replace instead of manually stepping though the whole file and browsing files/etc.

Finally I moved into the “how can I do this better” frame setting myself the goal of using a new command everyday for a while. I think this worked well and today I couldn’t see myself using anything else though getting here was a long process and I’m still learning new things (after 8 years).

vim is a serious time investment but one that is ultimately worthwhile in my opinion.

A couple of pieces of advice that worked for me:

Map leader to something comfortable *for you*. I can’t stand mapping it to a small key like comma. I have my leader mapped to and it’s made a huge difference.

In fact, all your key mappings should make sense to you. Also, check out other people’s vimrc files. You can find mine here:

https://github.com/xmlblog/dotfiles/blob/master/.vimrc

Sorry, the last comment omitted my leader which is SPACE.
Also, here’s a screenshot if you like: https://picasaweb.google.com/xmlblog/MyTmuxZshMuttTigSetup?authkey=Gv1sRgCPq-n77N2bbMNA#5602259719513821234

Ok, how do I get a list of symbols defined on the current open file? I’ve looked all over and can’t find it. I don’t want something so heavy as ctags (which generates a ctags file for the whole project). I just want method definitions for the file I’m currently viewing (exactly like TextMate’s cmd-shift-t).

O dear, o dear. I’ve been using Vim for a long time, but I didn’t know about ci….
It so effective and productive. Thanks

@Kirill Maximov, promoting RubyMine: I like RubyMine very much and use it since version 1.0. BUT: Having all these nice features is nearly worthless if my IDE keeps lagging and is unresponsive! Because of choose to switch over to vim as much as i can and use RubyMine mainly as a nice debugger.

Sublime Text 2, the editor I believe to be the true successor to TextMate (which, let’s face it, is abandonware), has just introduced Vintage mode. What’s nice is that it’s all implemented via its superb Python-based API. So you can easily hack on it and build your own stuff in. Awesome.

See the announcement here: http://www.sublimetext.com/forum/viewtopic.php?f=2&t=2609

Essentially, what we have is a hybrid of TextMate + Vim. Try it (it’s cross platform, so no excuses).

Vim is the Six Billion Dollar Editor. It is worth its weight in gold! It has a steep learning curve but you have to stick with it. I cannot code without it.

Also you have to configure .vimrc file. That is where you can really increase your Vim power. There are cool plug-ins available too.

Hi Mr. Katz,
I am making a series of pages to help
my nephew learn Vim (he is six, hah!).

I think if I can teach him Vim through a fun game
without him actually knowing it, it will be much less painless.

Please check this out when you have some
time: http://dogdevim.com/pages/games/learning_vim.html

Thanks!
– John Daniel Jimenez

*less painfull >.<

Charles Roper: the one excuse I can see is that ST2 is not FOSS. But the vintage mode (and its implementation as a plugin using the ST2 internal API) is really a killer-feature. It’s quite easy to add new commands and expand the compatibility layer.

@circuit_breaker Yes, you can use `Shift + Arrow Key` to perform keyboard-based selection while in MacVim’s insert mode. I love it because, while in insert mode, this OS-X style selection can be more efficient for quick tasks (vs. exiting insert mode, entering visual mode, then using vim motion commands to complete the selection, then pressing ‘C’ (Change, to begin typing) or ‘Y’ (copy into the primary and 0 registers) or ‘D’ (Cut-like / delete and place into the primary register)

If you’re determined to learn vi, for those times when you have a zombie *n?x installation that only has something like nvi available, it’s good to eventually learn to navigate text documents without the arrow keys. But to start off that way? Ugh. I had to do it in college, because we had a sadist of a professor in one class who insisted that everyone learn vi. Vim, however, is lightyears ahead of that.

I actually landed on this looking up things about Emacs, weirdly enough. I’m trying to make the switch, and I have to admit that I’m starting off by using evil, which makes the vim->emacs transition so much easier.

I’ve been using [g]vi[m] since the 1980’s and I (now) always use the mouse to position, highlight (especially double clicking to highlight a word), and scroll to a particular area of code using scroll wheel or scroll bar.

Plus I always use the cursor keys instead of hjkl. The days when this was not advisable are LONG gone. I’ve used them since I gave up using a falco terminal.

So shoot me.

I went through vimtutor at the time, took about 4 hours over a period of 2-3 days, and after that, I was already editing faster and more effectively than with any Notepad-derived editor I had ever tried. Perhaps, this article was meant as a joke, and I’m not getting it..?

I used to feel the exact same way until I tried vimtutor

After using vimtutor for an hour every day for a week and installing vim-rails + commandT plugin, I am now day 2 into using vim and have a pretty confident feeling that I won’t go back.

@ Joe Sak: glad to know I’m not alone. :-)

I’ll hazard a tip: when you have nothing better to do & feel like digging further into Vim’s capabilities, start Vim and type “:h user-manual” and you will be presented with a more detailed tutorial that walks you through most of Vim’s capabilities at your own pace.

The way I studied it was to split the screen vertically (:vertical help user-manual) so that you have another half-window where you can practice the examples. You can copy/paste them from the user-manual and use “Control-w w” to switch between panes. Hope you understand the above description… it’s a lot easier actually doing it than putting it in words.

Oh.. and if you’re still reading ;-) I’ll hazard another piece of advice: Look for a document by Bram Moolenaar (the Vim developer) called “Seven Habits of Effective Text Editing”..

CJ

Leave a Reply

Archives

Categories

Meta