Hacker News new | ask | show | jobs
by cassepipe 980 days ago
Dear Vim beginner, before getting a fancy keyboard, do remap Esc to some other key.

It makes no sense to have your most important key where it is nowadays.

The reason the back to normal mode key is ESC is because that key used to be much closer from the home row.

My personal preference is to use Caps Lock because each OS has an easy solution for this simple remap and since it's system wide you can use vim modes elsewhere too (zsh and gdb for me mostly). Also in general it's quite convenient to have escape so close.

Do what you will but please don't suffer uselessly for stupid historical reasons.

9 comments

This is good advice. But be cautioned--at some point you'll want "some other key" to be the left half of your spacebar or some other such nonsense. And then you'll be one of us. Forever.
Caps lock is such a waste of prime keyboard real estate, even for non-vim users!

For those who don’t use vim, just switching caps lock and control is probably better so you can copy and paste with less contortion.

For vim users, I highly recommend remapping caps lock to be control when held, and escape when tapped.

I jump between using a Mac and a Windows machine for development. Remapping capslock to ctrl/cmd feels more ergonomic, and has the added benefit of making it so I don’t have to remember which machine I’m on.
> caps lock to be control when held, and escape when tapped

Ooh, nice! How do you map it in Vim? Or in MacOS?

I always remap caps lock to control because, Vim or not, I still need control-something all the time. But I always wanted to remap esc to something closer to the home row, but never did since caps lock was already taken :) How do you map the held/tapped keys separately?

Thank you!! I just remapped caps lock to esc and I think I'm in heaven. I've always thought esc was painfully far away, but never thought to remap caps lock.
Just to add to the other ESC remapping suggestions:

Insert mode (i.e. i): space

Exit insert mode (i.e. esc): shift+space

Some terminals have issues with modifiers on keys like space but if you're a vim user on only 1-2 machines and can use something like Kitty then you should be OK.

Huh. I find ESC easier to type than Caps Lock because it is in the corner of the keyboard.

I used to have RSI and what solved it (over 15 years ago) was taking more care to hit the precise center of the key. Using my sense of touch to sense the key's exact location before even trying to activate the key helps me do that. When the key is on left edge of the keyboard, it is easier to do the determination of the exact location (of the left edge of the key I want) because I don't have to worry about accidentally activating the key to the left of the key I want. Caps Lock of course is also on the left edge of the board, just like ESC is, but ESC is also on the top edge, which is an additional help: the easiest keys to type in my experience are the ESC key and the left control key because they are in corners of the board. (The other two corner keys, "pause/break" and the right arrow key, are harder because of how far they are from the home row.)

I never understood the desire many writers on this site have of moving the hands as little as possible. More precisely, I understand the rationale, but I consider the rationale to be misinformed. If you don't move your hands (i.e., because you have a keyboard with only 36 keys or something), you still have to use your arm muscles to hold your hands over the board, and the human brain is better at movement than at using the muscles to statically counteract gravity like that. That is part of it, but there is more. When hitting a ball with a tennis racket, it is ergonomic to take a back swing, i.e., to move the part of the racket that will hit the ball in the direction opposite the direction you want the ball to go, before starting the swing. Very quick back swings are important in typing, too, for preventing RSI (for reasons I don't fully understand). And I think moving my hands around the board (i.e., in the 2 horizontal dimensions) makes it less likely my brain will put the relevant muscles in "freeze mode", which makes RSI more likely. Or something like that.

> Using my sense of touch to sense the key's exact location before even trying to activate the key helps me do that.

I like to use different kinds of keycaps on the same keyboard to give myself tactical hints for this reason. It's common to have `f` and `j` differentiated, but I also have different textures for differentiating the alpha keys from their neighbors and for what I consider "home" for my thumbs.

Vim stockholm syndrome ?

I don't know about RSI yet but I do know one thing : Vim workflow is to make a quick edit and then go back to normal mode as quickly as you can. This prevent accidental inserts and you are always back at the command center for your next edit. The same way some people understood most of the time is spent reading code rather than writing, vim's insight is that more time is spent doing edits than actually inserting text. So maybe strecthing your pinkie to the far (but admittedly easily locatable) corner of your keyboard is good RSI exercise I don't know but the Caps lock is just as easy for your finger to locate and don't require strechting. It's just better.

For me it's the same as them, and it's because I don't bother with home row typing. Too restrictive, my fingers don't easily bend that way. Instead I do a sort of whole-(laptop)-keyboard thing where I know where the keys are relative to the edges, and use my shoulders and elbows to move my hands as much as I use my wrists - no twisting needed, so Escape is as easy to hit as most other keys.
>use my shoulders and elbows to move my hands as much as I use my wrists

Yes, that is what I do. In particular, no muscle ever needs to stretch to anything close to the limit of its range of motion the way I type because the shoulders and the elbows can move over a much larger range than what is needed for moving the hand around its half of the keyboard.

Note that there is a third alternative, namely to keep the palm of the hand stationary and use the tiny muscles that move the finger left or right relative to the palm, which strikes me as even worse than bending the wrist left or right, and there is a keyboard called the DataHand that encourages, nay, requires, that:

https://deskthority.net/viewtopic.php?t=16008

This DataHand keyboard has very bad ergonomics, IMHO, and my guess is that switching to it causes more RSI than it prevents.

After using a keyboard with Esc even further away than usual, I've found myself using Ctrl-[ more often. I should look into remapping capslock.
Please do that, it's a simple option in the settings of any OS.

Why use such a convenient tool as vim if you have to make a weird combination for the single most important key in your editor ?

I know one gets used to anything but still.

(I personally believe it doesn't make you that faster but it does take away the dullness/repetitiveness out of editing)

Honestly even if you don't use Vim it's worth doing. I'm a big fan of interception-tools' caps2esc on Linux.
The reason why I recommended this simple remapping is because there's no need for any tool. In each OS there's a simple, GUI accessible even, option for that remapping.

Combining Ctrl + Esc is even better no doubt but it takes a bit more work

The jk solution is great but it won't be available in other vim modes elsewhere

Binding caps lock to control when held and escape if pressed alone is the greatest
I agree with this, but there is another default combination that is escape , right?

I realized that esc was difficult in vim when I was forced to change due to the original MacBook Pro Touch Bar.

Ctrl-[

It's not bad, but not all that comfortable on my left hand pinky finger.

That’s it! I have come to use this without thinking and I have not noticed any discomfort.
I experienced the same thing in another aspect of my life. My light switches at home can't light the room with just one switch for some reason. Each time I want to enter a room, I have to write LIT in morse with the switch. It was a bit weird at the beginning but now I got used to the pattern and I can do it under two seconds and I have not noticed any discomfort.
inoremap kj <Esc>

:)

It's a great idea but it's not portable in other simple vim modes that generally lack the possibility of such a configuration, and if they do provide it, now you have another configuration to take care of.

Why I like my solution : It takes three seconds to activate in any OS and it's available system-wide

I use this one, too.

I've seen a lot of people recommend jj, but that's part of something I type a lot, so I had to choose another. jk works okay too, because I don't use that acronym.

I thought I was the only one insane enough to do this.
There are dozens of us! Dozens!
This is so useful I have it baked into my keyboard!