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”

Good idea to leave it while taking your first baby steps in Vim.

You can achieve that with (rather than starting vim and hitting ‘i’):

set im
or
set insertmode

C-L to leave insert mode and C-o to execute a command

When learning vim, the best thing one could do is print out a vim cheatsheet, and keep in handy every time vim is open. Find a cheat sheet with all the basic commands… once you get most of those down, go find a cheatsheet that has more advanced commands, or commands that you havent yet committed to memory, and continue on in that fashion, till you achieve vim ninja status.

Also download other peoples vimrc’s… many coders put them on github these days.

Keep a browser window open too, to stackoverflow…. lots of great vim tips there.

i’ve been using emacs for over 25 years, so the comments about muscle memory are important: the keybindings might be weird (though you can change them if you’d like) but they work for me. in fact, i don’t really think about them anymore…i just edit. i’m sure the same is true for vim experts.

i really, really doubt i’d become more “efficient” if i switched to vim. or anything else, for that matter.

@drj: Cheat sheets is the worst possible way to learn Vim. It’s a bit like folks who try to learn a foreign language with flash cards. Ten years later, they know all the stuff on their flash cards alright, but they still can’t speak the language. Learning an editor is all about committing short sequences of commands to muscle memory in order to perform editing tasks (deleting a word, reordering sentences, cutting and pasting, etc.) QUICKLY and EFFICIENTLY, without having to THINK about it.. so you can focus on what you’re coding, writing… etc.

@Chris Jones: I’m sorry to be the guy that has to do this, but you need to take a step back and realize that you sound like one of the “vim masters” from the article. I was once feeling the EXACT pains Yehuda described (probably the same ones drj once felt too), and you are pretty wrong about your statement. The fact is, when you’re learning something new, you have to use whatever works for you, and cheat sheets, despite your bible-thump, can be instrumental in learning a new tool like VIM. You can’t “QUICKLY and EFFICIENTLY” learn a new thing if don’t have mental sight of how to accomplish your goal. One does not simply commit everything to memory at first glance, sir. I had this set to my background the whole time I was learning VIM and it turned out great: http://www.viemu.com/vi-vim-cheat-sheet.gif

I recently started using Vim but I am being drawn towards Sublime Text 2 which has support for a lot of Vim’s awesome commands. You can check it out here: http://www.sublimetext.com/2

Thanks for this! I’m around a lot of *nix admins / hackers who are convinced that vim is the One Twue Way to edit anything. They say the same things you said in your article: Don’t use the mouse! Turn off the arrow keys! No cheat sheets! Install it in Firefox! And then I have the same problem of vim having too steep of a learning curve to be able to get anything done in the short term.

So, I’ll ignore the zealots (people who speak in absolutes like that should be held in suspicion anyway) and do it MY WAY, which might be clunky and slow, but still lets me get things done in the short term while I learn a new tool.

Index cards are another good alternative, and can aid in learning all this stuff faster. For example, when you add another plugin (more screams from the Vim purists) you can bring on board a whole new set of commands and shortcuts to learn. Or say you just now need to learn about buffers. Make index cards, and use them until you don’t need them anymore.

When you’re older, you’ll find your “muscle memory” shot just like the rest of your muscles, and you’ll be thankful that you still have your index cards. :D

I know this is just regular Internet-forum-flame-wars… but here is a clever thoght I read once:

There are new tools and there are old tools. The new tools are great, productive but… maybe the interface will change, it will get bloated, the core developer will quit, etc. The old tools have been tested and are not likely to change by now, maybe will be here forever.

That is the number one reason to use vim or emacs and not any of the fancy new editors. Be productive, save time, learn to do a thing just once.

PD: Also there is VISUAL mode in vim that lets you use mouse the way you use it in every editor out there but with vi commands.

I learned VIM the “hard” / “true” way and was extremely excited about it. But some of my colleagues just installed MacVim and the janus plugin set: https://github.com/carlhuda/janus – and were instantly happy with that. They say it feels like “drop-in replacement” with much potential for improvement.

Hey I read about your tribulations with vim, and I have to recommend my own .vimrc file to you: https://github.com/bukzor/buck_dotfiles/blob/master/.vimrc

I’ve been working on it for ~6 years now. It’s meant to be very basic, only trying to fix little misfeatures and annoyances in vim. It’s long, but that’s because it’s well commented. It’s roughly arranged by order of importance or quality-of-life improvement, so if something seems too weird, just delete from there down :)

I also think that the advice to learn Vim by forcing yourself from the first day to use its commands instead of familiar system-wide MacVim shortcuts and mouse operations seems extreme.

If i were to recommend Vim to a friend, i would tell not to try to be productive with it for a few months, and view it as a game: find the minimal number of keystrokes to accomplish an editing task.

In my opinion, Vim turns editing text into playing Tetris.

Nice article. I have been working with (m)Vim for a few months now and it’s a completly worthy effort.
It takes a while to custumize it and learn it (+with all the nice plugins also to learn) , as well as choosing the ideal colorscheme (and font) and also the .vimrc file… and so on.
Sometimes i still use the arrow keys (so what?) but every day i learn a new ‘trick’ and that makes me happy…
I use commandT and NERTree but the one i am aware that i am missing (of this kind) is this one https://peepcode.com/system/uploads/2012/play-by-play-wycats-i-code.png .
I am a RoR beginner and i admit that the RoR file directory is harder to get then all the ruby language and rails (even including procs, lamdas and closures… ;) )
So if anyone knows which plugin (above link) is please tell me!…
By the way, because is vim and rails related:
For the RoR begginners like me, here are 2 small tips :
Run irb from vim with !irb
Or run irb in vim from inside irb with mvim or vi http://vimcasts.org/episodes/running-vim-within-irb/
Happy (vim) (rails) coding!

Hmm, I’ve generally suggested to people to run ‘vimtutor’ until bored, and then use as a basic editor and pick stuff up along the way.

Would this have put you off? I mean, vimtutor.

I guess I assumed that was how i learned vi (before vim) and that it would work for others.

Agreed. l33tism must die for humanity to survive.

I learn vim by small, specific edits. I follow Bram Moolenaar’s advice to recognise and try-out efficient methods and to reinforce the ones I need. I expect this process to take a year or two and that’s fine. the thrill of Vim_Powa™ keeps me keen.

This post challenged me to give vim another shot, and this time it stuck—I’ve been in love with vim for months now. Some thoughts for fellow newbies:

(1) As has been said, building a good .vimrc in the beginning is crucial to make vim do by default things you’re used to in your old editing environment. Some of the commands I’ve found most useful to that end there are set number (line numbering), set hidden (work with multiple unwritten buffers), syntax on (highlighting), set ignorecase (default case-insensitive searches), set hlsearch (highlights search results), set wrap (line wrapping), set mouse=a (so you can use the mouse if necessary—not a good habit, but definitely a timesaver in certain situations), and set whichwrap=[options] (keys/commands that traverse line wraps). Also in your .vimrc, remap some of the keystrokes with unintuitive results. For me, the main ones are “nnoremap j gj” “nnoremap k gk” “noremap gj j” and “noremap gk k” to give j and k more typical row-traversing rather than line-traversing behavior.

(2) One customization has to do with the only time I was ever frustrated with vim. To avoid scrolling with the mouse, I use ctrl-u and ctrl-d all the time to scroll up/down by half-page. The problem is, in insert mode, Ctrl-u by default undoes all typing on your current line—i.e., DELETES your current line—in a way that is not recoverable by an undo. While the text in theory can be recoverable immediately thereafter (http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U) if you’re lucky enough to realize what’s happened, it’s still very frustrating (and when it happened to me, I didn’t understand the situation enough to recover my text. So I use “imap ”

(3) In terms of restoring productivity lost during the switch, make sure you understand text objects and how to use the *i*nner/*a* block commands to quickly perform actions on them. Also start using t/T and f/F. This stuff alone more than makes up for almost any other “costs” of switching to vim.

Apologies for the dropped text—what was I thinking using angle brackets? To avoid the consequences of ctrl-u in insert mode, my .vimrc has “imap [C-u] [Esc][C-u]” (with [] replaced with angle brackets, of course, and for both u/c and l/c u).

Vim!? Who can even think about using ‘that’ when Emacs is around!? (specially version 24.2.1 which rocks)

Fun how I’m experiencing exactly the same these days :) It’s about maybe the 4th time I try to switch to Vim in two years but this time I gave MacVim a try and guess what ? It’s not as painful as before AND I FINALLY gain efficiency (slowly but surely).

Cheers!

@ADMK; do you have some good short introductions to the i(inner)/a(round) stuff, as well as f/F t/T commands? I have seen hints and bits but a short intro on what it’s about and why it’s cool could probably do a lot to help met started using it.

@emil

f/F t/T commands are for jumping to the next (lower case) or previous (uppercase) occurrence of whatever character you hit next. f/F goes directly to the character while t/T goes to just before the character.

Handy for jumping around but much handier when used with other commands. For instance “cfu” will wipe out everything between the cursor and the next u, leaving you in insert mode (change find u). ctu will do almost the same but instead changes everything up to the u, leaving it there. A common use for developers would be ct) meaning ‘change everything from here to just before the closing paren. Uppercase versions do the same, just backwards from the cursor.

Speaking of parens, that’s a great use for ‘i’ or inner. Put your cursor inside of a function declaration like foo(){cursor here}. now, hit ‘ci{‘ and vim will wipe out everything *inside* the {} and leave you typing. yi{ to yank it. di{ to delete it. gUi{ to make it all uppercase… I’m using { here but it will work with most anything like ” or ‘ or ( or [ or whatevs. One that I missed for a while was t. in this context, t is tag. so cit inside of an html block while change the contents of the tag. cat will change the tag and it’s contents.

Should get you going. There are much better explanations of this stuff on the internets. :)

I had virtually the same experience as you, though my starting and ending points were different. I’m an old mainframer and my experience was to get it right on the punch cards and make sure the greenbar reads the way you like and then the clunky old line-editors won’t mistreat you too much. But some of my buddies were quickly moving up to full screen (which seemed to highlight the follies of many of their global-search-replace’s).

Somehow some VAX users had worked their way into my social circles, and they just couldn’t figure out why we didn’t use vi. I had much the same experience as you did initially, and I had to wonder whether converting us to vi wasn’t a way to show off and make us look foolish at the same time.

There could be a “vi turning point story” chronicle with the number of ways one discovers productivity with Vi/M. Many years later I decided to give it another chance since our limited resource was overloaded and vi was ‘light.’ It was meant to be a temporary solution, just until we got all the boxes online that we were promised in the first place.

But a funny thing happened: I decided to find out how people adjust to vi. I read a criticism from an Emacs user who said, “Just be prepared to be hitting escape for most of your life.” I sat down at my keyboard and smacked escape with my left pinkie a few times and I decided that I could live with that.

Enter Bram Moolenaar: After I started my escape-punching life and we had machines that were up to application level rather than minimal system loads, somebody said, “Why don’t you just use ViM?” What’s that? I asked: “It’s Improved vi — vi only better.” Now I do get a little frustrated when I have to go back to old vi because my once-cryptic keystrokes have now become automatic.

But getting used to switching between modes (hitting escape all my life) was what made the real difference for me.

The issue with incrementally learning vim is that it is a completely different way of editing text. It isn’t simply notepad with a bunch of shortcuts.

Now you can use it like that by staying in insert mode (which is what you did), but you are not actually learning vim. The entire purpose of vim is that it has an edit mode and an insert mode. This isn’t some purist, elitist viewpoint at all. That would be like saying someone who insists on driving an automobile instead of pushing it is a “purist”.
At some point, you will have to make the jump and stay in edit mode (by hitting ESC) until you have to actually INSERT text.

I’ve been using Vim for years, and I still use the mouse and arrow keys. Not because I couldn’t switch to using HJKL, but because a) why should I? b) it makes it much easier to switch back to another editor if I have to, and I still get all the productivity boosts of everything else Vim has to offer, like all the shortcuts, regexes, and everything else. I challenge anyone to work their way around code faster with HJKL than I can with arrow keys and/or mouse.

Great article! I’m sure I will be flamed for this, but why–in the 21st century–is anyone using these kinds of text editors? Is there nothing else out there? I used vi almost 20 years ago and it was painful not being able to use a mouse or use the usual keyboard commands (apple key + s, f, q, x, v, c, etc.). I had to dive back into it now because I couldn’t get the permissions just so on the file I wanted to edit in TextEdit so I had to sudo vim it. I’m glad it is easy to locate resources to remind me what the basics are otherwise I would have been lost.

single BIGGEST productivity tip in VIM: Switch your Esc and Capslock Key – your pinky will thank you from the bottom of its innermost muscle.

Use AutoHotkey on Windows to easily to this.
On Linux use xev to get the keycode and then xmodmap.

vi is for server administrators. Why? Because you find it on any (*nix)server and it works perfectly with a [text-]shell. So that is the main reason to learn vi, it is simply the best editor – just looking at editors, not operating systems – when it comes down to a text file, a shell and an urgent task.

And for those like me that like plugins in vim/macvim now you have :

http://vim.spf13.com/

At least for me it has everything that I need and some pretty nice to have that didn’t know were out there.

Vi has some powerful features that (almost?) no other typical modern editor has (e.g. number of times to execute command). I suggest you using a “mixed” editor (e.g. viPlugin for Eclipse -http://www.viplugin.com/index.htm-) and start using Vi commands as much as you can instead of the editor’s mouse or shortcuts. This will make the learning curve less steep and you can always use your typical commands when you don’t know Vi’s. I’m no vi master, but seriously, once you start using some Vi commands (e.g. d, o…), you can’t live without them anymore :)

I only learnt Vim once I had a Vim master within arm’s reach of me every day at work. Whenever I got stuck, I could just shout a quick “help!” at him and he’d help me, it was quicker than searching for help on the Internet without knowing the terminology. Like most Vim users, he was a Vim evangelist, so he didn’t mind, I think :)

Agree with the last sentiments. There are some ways to do specific processes faster than others, not necessarily all with VIM. Learn them all, not one or the other.

vi(m) is an editor that people learn to use in case they find themselves in an emergency situation (sometimes when the system is badly broken, the only text editor available is usually vi), so the only commands that one really needs to know are i (insert), (stop inserting), :q (quit) and :wq (write and quit). For everything else, you’re better off with a proper text editor. Such as Emacs.

Why don’t you just start with vi-mode plugin in Eclipse (vrapper) or VsVim in Visual Studio, or Kate, or MonoDevelop. If you can handle just the navigation and mode switching, which i mean really should take a minute, then you don’t have to worry about anything else as you can still use the shortcuts your used to. I can’t imagine how this would slow you down, over time you’ll learn new tricks to speed up your text editing.

Just spend some time with vilearn or vimtutor to learn the basics. Then read VIM book. Not everyone has to be “vim master”. I use hjkl because in server rooms I have different keyboards (eg. PC, Sun) and no mouses. Through many years of practice it got into my muscle memory so even on workstations with mouse/arrow keys I prefer hjkl only. I also don’t use any external vim plugins so I can feel comfortable with pure vi on systems where it’s the only available interactive editor.

It’s important to remember that there isn’t one true way of using vim. If you feel it’s too hard for you, use something easier. If you use arrow keys and it works for you – great. If you need to be flexible with broad range of operating systems and hardware you need to invest some time (like with any other serious subject).

“I challenge anyone to work their way around code faster with HJKL than I can with arrow keys and/or mouse.”

Wrong battle. Fully vetted users navigate as much as possible using search commands, not motion commands. This is excellent motivation for being very thoughtful and consistent about how you name your code entities, and thereby makes locating yourself within the code virtually instantaneous. Your advice is like preferring race cars to bikes, when you are capable of teleporting.

Beyond that, it sets you up for further utilizing your previous searches inside more powerful commands.

Learning Vim incrementally is a fine approach; one might say it’s the only sane approach. There is simply too much in Vim to learn all at once. Furthermore, if you’re coming from another editor with a wealth of habits and muscle memory, then you are struggling against two fronts – learning the Vim Way while unlearning the old ways.

In the vein of learning the Vim Way, I humbly suggest https://github.com/dahu/LearnVim

I’ve been using VIM more and more and in the last couple of days really learned enough to not use anything else. I am using janus to set up my .vimrc since I fudged it up and can say that I am really happy with how things are working. I made some modifications to janus but can’t seem to find where to put `laxcomma`
I like my commas on the left-hand side, any help would be most appreciated :)

Leave a Reply

Archives

Categories

Meta