Learning Vim

· Read in about 5 min · (886 words) ·

Is it worth it?

Definitely seems to be. I’ve looked at VIM in the past, tried it out too a couple of times or more, failed miserably(mostly within a day or two) and then wondered Why nutheads use VI. This would usually be followed with going back to the comfort of Emacs. I think over the years, I’ve spent more time customizing Emacs than actually getting any work done with it. And somewhere that felt wrong. In light of that, the minimalistic VIM looked attractive and worth another try.

So what was different about this time?

So this time things worked out a bit better. Rather than firing up VIM, spent some time reading through other’s experiences on picking up VIM. And the first thing I did right was to disable the arrow keys in normal mode (I still have them in insert mode)

Disable arrow keys
    noremap   <Up>     <NOP>
    noremap   <Down>   <NOP>
    noremap   <Left>   <NOP>
    noremap   <Right>  <NOP>

Once you have that bit, you’re forced to use h/j/k/l. And while h/j/k/l muscle memory is built up within a week, the thing that’s really happening behind the scenes is that you don’t actually use h/j/k/l that much - instead you move around using more efficient movement commands.

Soon you’ll find that you don’t tend to remain in insert mode…​ Vim’s really supposed to be used in Normal mode with quick bursts of jumping around file(s) and hopping into insert mode for a quick edit followed by a return to Normal mode via Esc

The next thing you probably want to do is to keep your hands on the home row always. I like jk to trigger Esc key. jj is also a popular choice. When vim was written, the Esc used to be at the place where we have the totally useless CapsLock nowadays. While there are hardware and software key remappers, you probably want to start with the following

Remap jk to Esc
"inoremap <esc> <c-o>:echoe "use jk"<cr>  (1)
inoremap jk <esc> (2)
1 - Uncomment if you like to be nagged a bit
2 - Only in insert mode

There’s tons of resources/cheat-sheets on the web - but the approach I followed was to figure out some small keystroke when I needed it. What that meant was that I could get work done - but at the same time get more efficient gradually.

Customizations

VIM out of the box is pretty badly configured - and that’s part of the reason that people seem to shy away from it. In fact, all the times that I tried out VIM before, I didnt even come close to cusotimizing my .vim. There are folks who have curated vim dotfiles on github etc - but my advice is to stay away from them. You should know what goes in your .vim and be in control of thatrather than getting a bunch of things in your .vim that you dont understand. Just so you know, looking at the github history for my vimfiles repo - the initial commit was 3 months ago - but after that, all the commits have come in only in the last 4 weeks.What that means is that while I put in a vim file initially, I didnt do much with it initially since I was just getting a hang of the basics. Once one becomes comfortable with the basics, one moves to customizing the vim environment more and more.

Parting words

To summarize, VIM definitely seems nice once you invest into it. It’s easy to drop off in the initial stage and not go any further - and I believe this is what happens to the vast majority of folks who try it out. However, once you build that initial comfort level,it feels light, fast and easy.Start easy, persist, and customize bit by bit - you’ll feel yourself going from struggling with Vim to feeling comfortable and then to customizing your environment for an even better experience with VIM.I’ve definitely been more productive with VIM than I ever felt I was with Emacs - and these posts to my blog from Vim part of that.Besides that, I’ve used VIM effectively with a decent sized js code, html markup etc and felt the speed of editing inspite of still being a noob in Vim terms.

2021 update

Can’t believe it’s been close to 10 years since I got into Vim. I’m typing this on Neovim and frankly, I’m glad I persisted with Vim. I’m still no expert user or anything but having a Vim/Neovim instance around is just being home!

Some more things to consider if you do manage to land here

  1. No one’s ever going to pry Vim/Neovim away from you. It’s going to be there for ever and it’ll be there on every server you decide to log on to. I’d much rather commit to muscle memory that on thing that’s going to be always around - instead of VSCode, Eclipse, Idea keymaps. I’ve used all of them (and still do) - but almost always with my Vim bindings.

  2. Vimium on the browser for mouseless browsing

  3. I realized that in retrospect, this post was light on details of initial configuration - so I updated the section above a bit

Occupational hazard

You might catch yourself typing vim keystrokes in Word or Outlook! 😃