Hacker News new | past | comments | ask | show | jobs | submit login

The most productive mapping ever: imap jj <ESC>.

No more having to reach for the escape key.




Even better:

    imap jk <ESC>
    imap kj <ESC>
I just hit both and j at the same time with my pointer and index fingers so it's essentially one keystroke.


`kj` has worked really well for me (except, actually, when trying to write a blog post about a recent trip to Reykjavik, but that's the one time it's bitten me versus the shitton of time it's saved). I also have `zkj` mapped to `<ESC>:w<CR>` to save AND exit insert mode.


How does this work? What if you are in insert mode and actually want to type j or k?


It's the combination jk (or kj) that is set up to switch from insert to normal mode. The idea is that this combination rarely occurs in English text. The drawbacks are a slight delay in cursor movement when typing j or k as vim waits to see what comes next, and momentary confusion when you inevitably need to actually insert these sequences.


I much prefer mapping Caps Lock to Escape at a different level (with xcape -- caps is both my i3 modifier and my Escape key). That way, when I SSH into something and use vim or a shell it still works (or when I vim as root), and anything with a vim mode will just work.


ICBW, but I believe Ctrl-[ is already available, and works the same.

For me, having remapped Capslock to Ctrl, this is a dead simple way of hitting Esc without going as far off homerow.


I had jk mapped for a long time and thought it was safe. Then one day I actually had to type it as text, and it took me a moment to figure out what was wrong. I'm retraining myself to use ^[ now.


I don't think the speed hit you take when you actually have to type 'jk' should be a dealbreaker. It rarely comes up, and when it does, you can use e.g. '<C-v>j<C-v>k' or 'jjkak'.


Map Caps Lock to Ctrl. Then use Ctrl-C. You can keep your hand in home row.


I have done something similar: I mapped Caps Lock to Esc on system-wide level, and it has been remarkable since.

The only pitfall is when you start using someone else's computer and putting caps everywhere.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: