0

Recently I was reading http://learnvimscriptthehardway.stevelosh.com, and he said a very fast way to improve your speed in vim is to do inoremap jk <esc>. Sure, that made sense.

Then when I next starting using Visual mode, I noticed jk did not work. Sure, yeah, that makes sense. So I added vnoremap jk <esc> also.

Next I realized that I needed to use <esc> in normal mode too. This is useful when you want to cancel a command, say you accidentally typed in a huge number, and were going to press dd when you caught yourself. To get rid of the count, you need to do <esc> in Normal mode as well.

So I basically just removed everything else and put noremap jk <esc>. But obviously I can no longer smoothly use j to scroll down in vim since it is waiting to see (hanging) if I enter k.

If I can't use jk in all my modes then there's no point in doing this mapping.

So: Is there any way to universally and efficiently use something like jk to escape?

1

The combination jk is not thought as a general replacement for <esc> in all modes. It's just for insert mode to save you from moving your finger up to the <esc> key. In all other modes you have to use "normal" <esc>, but then jk just moves the cursor down and up -- so nothing happens.

There are users out there who redefine their keyboard layout and define the<CapsLock> key as <esc>. Then you can type <esc> with the litte finger of your left hand. (My typing with that finger is so imprecisely, that I often hit <CapsLock> when I want to hit <Shift>, so I redefined <CapsLock> as <Shift>.)

I have a lot of customization, but I did not do any special mapping for the essential movement/editing/... keys. That way I have less problems when I work on a Vi/Vim without my setup.

| improve this answer | |
  • 1
    Nice thing about having jk defined in insert mode is that when you're not in insert mode and use the cursor just goes down and back up and you've done nothing and gone nowhere. – user13081 Oct 21 '19 at 9:24
  • @GypsySpellweaver Good Point will Update later – Ralf Oct 21 '19 at 11:37
  • Just to add on, for years I had shortcuts to a couple of essential combinations (save, quit, window movement, jk escape, etc)—every once in a while, I would have to go somewhere without my setup. It was painful: I disabled all but the save and quit shortcuts, as those never caused issues (only minor hiccups). I rarely go places without my files, but it happens. – D. Ben Knoble Oct 21 '19 at 13:02
  • @D.BenKnoble But just to be clear, you only used jk in insert mode, and not visual mode and normal mode, where you used Esc instead (disregarding your other mappings). This seems very inconvenient to map two things for esc – herophant Oct 21 '19 at 17:46
  • @herophant oh it is—but yes, I only used jk in insert mode until ditching. Now I just hit escape all the time. More convenient, better muscle memory. My issues now come from mapping CapsLock to Control at a system level, so I cannot hit control keys on any one else's keyboard! Anyway, I see people doing this jk thing everywhere. I'm not against it, per se, but I grew tired of the mental divide. – D. Ben Knoble Oct 21 '19 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.