tadhg.com
tadhg.com
 

:imap jj <Esc> and :Bclose in Vim

13:24 Mon 22 Feb 2010. Updated: 03:56 30 Dec 2010
[, , ]

I remain rather happy with Vim, and it’s already been worth the effort of switching over to it. I’ve encountered some annoyances along the way; here are a couple of them and some solutions.

The first is that I quickly found myself wanting to exit Insert mode very frequently and not liking the stretch from my typical hand position to the Esc key. I know that some people insist that the only way to deal with this is to remap CapsLock to Esc, while others remap CapsLock to Ctrl and use Ctrl-C instead of Esc to get to Normal mode. Neither of these approaches appealed to me. Seth reminded me about another approach, one I thought would be too awkward: mapping jj to Esc within Vim.

I’d originally rejected that because it simply seemed wrong to have normal characters screw around with modes while in Insert mode—that’s what modifier keys are for! On the other hand, I don’t type “jj” too often[1] and so it seemed worth trying, especially since I wasn’t set into any of the other Vim habits yet.

It works extremely well. Being able to get out of Insert mode without moving my fingers off the home row is extremely smooth and fast, and I’ve found that after a very short period I was used to it and exiting Insert mode more fluently. Very occasionally I notice the delay when I’m typing something with a “j” in it, but that’s pretty minor, and sometimes I forget and still hit Esc, but I think that’ll go away. The only other problem I see is trying to use “jj” in other modes, like Ex mode, and expecting it to work as Esc, but I suspect that won’t be a major problem. So if you aren’t completely set in your Vim editing habits, or you’re having problems with your current setup for some reason, I highly recommend trying :imap jj <Esc> out despite its seeming wrongness.

Another annoyance I encountered was that closing a buffer would also close the window it was in, and I often want to keep the window setup (usually a split) that I have. I got around this first by using the BufExplorer plugin to close files, which is definitely useful, but then I discovered that someone wrote a script to do exactly what I wanted: :Bclose. It’s worked fine so far, and if you’ve also been annoyed by that behavior I recommend trying it out.

[1] The only even vaguely plausible reason to do so I came up with was the MTG card El-Hajjâj.

Leave a Reply