News for hackers. Stuff that matters.
Re:Forty Years of Programming by cassepipe on Sunday October 08, 2023 @08:25PM (#37815649)
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.

Re:Forty Years of Programming by jfdi on Sunday October 08, 2023 @09:22PM (#37815958)
inoremap kj <Esc>

:)

Re:Forty Years of Programming by qup on Sunday October 08, 2023 @10:19PM (#37816290)
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.

Re:Forty Years of Programming by Clever321 on Sunday October 08, 2023 @10:20PM (#37816293)
I thought I was the only one insane enough to do this.
Re:Forty Years of Programming by bbotond on Sunday October 08, 2023 @10:34PM (#37816371)
There are dozens of us! Dozens!
Re:Forty Years of Programming by precompute on Monday October 09, 2023 @05:22AM (#37818550)
This is so useful I have it baked into my keyboard!
Re:Forty Years of Programming by cassepipe on Monday October 09, 2023 @06:51AM (#37819006)
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

Re:Forty Years of Programming by hcs on Sunday October 08, 2023 @09:24PM (#37815972)
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.
Re:Forty Years of Programming by cassepipe on Monday October 09, 2023 @06:54AM (#37819017)
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)

Re:Forty Years of Programming by Zamiel_Snawley on Sunday October 08, 2023 @09:25PM (#37815979)
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.

Re:Forty Years of Programming by el_benhameen on Sunday October 08, 2023 @11:45PM (#37816743)
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.
Re:Forty Years of Programming by alentred on Monday October 09, 2023 @08:35AM (#37819786)
> 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?

Re:Forty Years of Programming by whhuh on Monday October 09, 2023 @07:46PM (#37826889)
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.
Re:Forty Years of Programming by jLid on Sunday October 08, 2023 @09:34PM (#37816028)
Binding caps lock to control when held and escape if pressed alone is the greatest
Re:Forty Years of Programming by __MatrixMan__ on Sunday October 08, 2023 @09:36PM (#37816045)
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.
Re:Forty Years of Programming by hollerith on Sunday October 08, 2023 @09:50PM (#37816118)
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 in 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 this determination of the exact location 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 do, before starting the swing. Very quick back swings are important in typing, too (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 more likely I will take these very-quick back swings while typing. Or maybe when I don't move my hands enough, the arm muscles "go into freeze mode" which makes RSI more likely.

Re:Forty Years of Programming by cassepipe on Monday October 09, 2023 @07:00AM (#37819061)
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.

Re:Forty Years of Programming by Izkata on Monday October 09, 2023 @09:41AM (#37820373)
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.
Re:Forty Years of Programming by hollerith on Monday October 09, 2023 @10:04AM (#37820565)
>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.

Re:Forty Years of Programming by __MatrixMan__ on Monday October 09, 2023 @11:13AM (#37821289)
> 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.

Re:Forty Years of Programming by pylua on Sunday October 08, 2023 @10:11PM (#37816247)
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.

Re:Forty Years of Programming by jodrellblank on Sunday October 08, 2023 @10:46PM (#37816432)
Ctrl-[

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

Re:Forty Years of Programming by pylua on Sunday October 08, 2023 @11:00PM (#37816505)
That’s it! I have come to use this without thinking and I have not noticed any discomfort.
Re:Forty Years of Programming by cassepipe on Monday October 09, 2023 @07:04AM (#37819083)
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.
Re:Forty Years of Programming by 000ooo000 on Sunday October 08, 2023 @10:30PM (#37816352)
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.

Re:Forty Years of Programming by niederman on Sunday October 08, 2023 @11:37PM (#37816692)
Honestly even if you don't use Vim it's worth doing. I'm a big fan of interception-tools' caps2esc on Linux.
Re:Forty Years of Programming by cassepipe on Monday October 09, 2023 @06:49AM (#37818999)
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