News for hackers. Stuff that matters.
Re:Modeless Vim by cassepipe on Tuesday January 16, 2024 @08:02AM (#39012810)
My usual comment on any thread touching vim, as an answer to all hypothetical comments talking about how vim never clicked :

Remap the Escape key to CapsLock else you will never like vim (provided you are a normal person)

It's the most important key and you should punctuate all your inserts with it. So it'd better not be the key that's the furthest away from your fingers. The reason that's the case is an historical accident.

Don't be a victim. Remap.

P.S : Yes, I know about people using Ctrl+[, or Ctrl+C, I know you got used to it but one gets used to anything, it does not mean it's good. A weird combination isn't great and Ctrl + C has some quirks --> https://vi.stackexchange.com/questions/25764/use-control-c-i...

P.P.S : Yes, I know about `jk` it's clever ok but my mapping is system-wide and now I enjoy Escape being at the right spot for bash, zsh, fish, gdb, firenvim vim modes at no configuration cost.

Re:Modeless Vim by wruza on Tuesday January 16, 2024 @08:14AM (#39012891)
“Doesn’t mean it’s good” doesn’t mean it’s a problem either. Also, people prone to remapping already have their Ctrl there.
Re:Modeless Vim by cassepipe on Tuesday January 16, 2024 @08:33AM (#39013076)
Life can be beautiful we don't have to suffer because it's already there.

Remapping takes less than 5 seconds in MacOs and Linux. 2 minutes in Windows. And you only have to set it up once.

Also my left pinkie never misses CapsLock and I don't even have to think about it. Can't say that's the case for Ctrl+[ which I have used extensively for one year. I am really happy I switched.

Re:Modeless Vim by carb on Tuesday January 16, 2024 @08:36AM (#39013097)
What do you do when you need Ctrl in non-vim contexts?
Re:Modeless Vim by cassepipe on Tuesday January 16, 2024 @11:19AM (#39015079)
I just press Ctrl ?

But frankly I don't use Ctrl that much. Ctrl + L/K in Firefox (I use vimium but I prefer the native bar) And I have Ctrl + J/K to switch terminal tabs In vim I only rarely use Ctrl + I/O

Re:Modeless Vim by carb on Tuesday January 16, 2024 @05:40PM (#39020151)
Are you often working within the command line? I don't use vim bindings elsewhere so I use these a lot: "Edit a command line" section on https://support.apple.com/en-gb/guide/terminal/trmlshtcts/ma...
Re:Modeless Vim by carb on Tuesday January 16, 2024 @08:35AM (#39013092)
Yeah I use Ctrl far more often than Esc as I'm usually navigating code and reading it vs writing it, so Caps Lock -> Ctrl is more valuable.

Additionally, I use Ctrl outside of vim very frequently as I keep my terminal key bindings native, which means all of the command line control patterns use Ctrl (jump to front, jump to back, cut (forwards/backwards), move by word, reverse search, etc etc)

I'm still of the opinion that Ctrl+[ like the OP said would be mentioned is the best because (1) it's native and (2) it uses both hands so it's almost as fast as hitting a single key and requires no hand contortion.

- 14 year exclusive vim user

Re:Modeless Vim by hmeh on Tuesday January 16, 2024 @09:03AM (#39013358)
Por que no los dos? I map caps lock to escape on tap, ctrl on hold.
Re:Modeless Vim by lozf on Tuesday January 16, 2024 @09:36AM (#39013667)
… and set "Both Shift Keys" to toggle caps lock.
Re:Modeless Vim by camtarn on Tuesday January 16, 2024 @08:39AM (#39013127)
> Remap the Escape key to CapsLock else you will never like vim (provided you are a normal person)

I guess I'm not a normal person then? Never bothered doing the remapping and I've been an enthusiastic Vim user for a decade.

Re:Modeless Vim by cassepipe on Tuesday January 16, 2024 @11:11AM (#39014981)
I don't know you but that is likely.

Most people are not believers and when they find something inconvenient they abandon it. Most people do what most people are doing :-) That's not the case for me. I am a believer, I use Firefox, Signal and vim, not Chrome, WhatsApp or VsCode. And I like it that way. The problem with being a believer is that you tend to downplay issues and that can bite you sometimes. I know because I have been been bothered by Escape being too far away for one whole year and use the weird combo instead. Surely there was a good reason for things being that way but I finally asked it turned out there was not.

Maybe you are the rare person that has very long fingers or whatnot and it's not inconvenient for you but you most likely are a believer :)

Re:Modeless Vim by camtarn on Wednesday January 17, 2024 @12:15PM (#39030525)
Haha, yes, this is very true. I was the guy who gave a lunchtime lightning presentation on why to use Vim (TL;DR: automating repetitive actions using the . key, macros, :global, :normal etc etc) :)

I use jk to get out of Insert mode on my local machine, and ctrl-C on remote machines where I don't have my .vimrc.

Re:Modeless Vim by MSFT_Edging on Tuesday January 16, 2024 @08:48AM (#39013224)
Smacking the escape key constantly is probably my favorite part of using Vim. It has me smacking escape all the time to see what it does in other apps. I love when esc is just mapped to a "stop doing that" or "go back".

Also doing embedded stuff, I find the caps lock key nice for when typing out a few defines or macros.

Re:Modeless Vim by dinkleberg on Tuesday January 16, 2024 @09:11AM (#39013420)
Haha I’d hate to know the number of form modals I’ve closed out of after instinctively hitting escape.
Re:Modeless Vim by joenot443 on Tuesday January 16, 2024 @08:59AM (#39013316)
> Remap the Escape key to CapsLock else you will never like vim (provided you are a normal person)

I think this is great advice for EVERYONE, vim user or not. Someone else made this suggestion on HN some 8 years ago and I haven't looked back since.

CapsLock is essentially useless for modern computing needs, but having a No/Cancel/Quit/Esc button immediately under your left pinky is fantastic. Your brain will get used to it in a day or so, give it a try!

Re:Modeless Vim by joshmanders on Tuesday January 16, 2024 @12:12PM (#39015780)
If I remap CapsLock to Escape, then how will I enable cruise control for awesome mode?

But seriously, I have hitting escape muscle memory engrained, I cannot remap it to any key because I won't ever think to hit capslock even if it's ergonomically "better"

Re:Modeless Vim by TotempaaltJ on Tuesday January 16, 2024 @12:26PM (#39015976)
I thought that, remapped it, and it turned out to be incredibly easy to swap over. I think it's because it's so much nicer to use.
Re:Modeless Vim by joshmanders on Tuesday January 16, 2024 @12:46PM (#39016240)
My point is that it's NOT nicer to use for me.

I just instinctively did it to see my motion and it's an awkward feeling for me to move my left pinky over to the capslock key, definitely something I have to be mindful of doing to make happen and probably will take a long time for me to get used to.

Meanwhile, I actually extend my ring finger up and barely touch the escape and move it back down, all of that is very comfortable for me and I can do it without looking 100% of the time and never miss it.

Re:Modeless Vim by zeroxfe on Tuesday January 16, 2024 @09:13AM (#39013435)
Yes, CapsLock is useless, and I've been remapping it to Ctrl since forever, which serves me a lot more than Esc.
Re:Modeless Vim by cassepipe on Tuesday January 16, 2024 @10:58AM (#39014806)
It can be both if you care to. You don't have to choose
Re:Modeless Vim by Toorkit on Tuesday January 16, 2024 @01:48PM (#39017103)
I've done Esc-on-single-press-Ctrl-on-hold once, but some games don't recognize the Esc press. Couldn't get to a menu anymore :P

Currently just have Esc on the CapsLock.

Re:Modeless Vim by sodapopcan on Tuesday January 16, 2024 @09:24AM (#39013530)
Best use for capslock in my book is tap for escape, hold for ctrl.
Re:Modeless Vim by ta988 on Tuesday January 16, 2024 @10:55AM (#39014759)
Where do you map it that way?
Re:Modeless Vim by sodapopcan on Tuesday January 16, 2024 @11:27AM (#39015151)
As my sibling commenter said, use Karabiner Elements if you are on macos. Though it's not an out-of-the-box thing.

Add this config to ~/.config/karabiner/assets/complex_modifications/custom-capslock.json

    {
      "title": "Change caps_lock to Esc and Control",
      "rules": [
        {
          "description": "Post Esc if Caps is tapped, Control if held.",
          "manipulators": [
            {
              "type": "basic",
              "from": {
                "key_code": "left_control",
                "modifiers": {
                  "optional": [
                    "any"
                  ]
                }
              },
              "to": [
                {
                  "key_code": "left_control",
                  "lazy": true
                }
              ],
              "to_if_alone": [
                {
                  "key_code": "escape"
                }
              ]
            }
          ]
        }
      ]
    }
and then in the GUI enable it in the Complex Modifications tab. Last you need to map "capslock" to "left_control" in the Simple Modifications tab.
Re:Modeless Vim by linsomniac on Tuesday January 16, 2024 @12:56PM (#39016372)
Ooh! Can I do this with "z" and "/" (letter if tapped, control if held)?
Re:Modeless Vim by sodapopcan on Tuesday January 16, 2024 @01:09PM (#39016514)
My GUESS is that it would be something like this:

    {
      "title": "Hold z or / for control",
      "rules": [
        {
          "description": "Hold z for control",
          "manipulators": [
            {
              "type": "basic",
              "from": {
                "key_code": "z",
                "modifiers": {
                  "optional": [
                    "any"
                  ]
                }
              },
              "to_if_alone": [
                {
                  "key_code": "left_control"
                }
              ]
            }
          ]
        },
        {
          "description": "Hold / for control",
          "manipulators": [
            {
              "type": "basic",
              "from": {
                "key_code": "/",
                "modifiers": {
                  "optional": [
                    "any"
                  ]
                }
              },
              "to_if_alone": [
                {
                  "key_code": "right_control"
                }
              ]
            }
          ]
        }
      ]
    }
Re:Modeless Vim by sodapopcan on Tuesday January 16, 2024 @01:06PM (#39016486)
Yep! You can do whatever you want with complex modifications. The only tricky part is figuring it out. It shouldn't be TOO different than the above if you replace the appropriate values.
Re:Modeless Vim by ink_13 on Tuesday January 16, 2024 @11:16AM (#39015047)
Karabiner-Elements will do this for you on Mac.

I consider it indispensable.

Re:Modeless Vim by wonger_ on Tuesday January 16, 2024 @01:58PM (#39017285)
I use this executable for Windows: https://github.com/ililim/dual-key-remap
Re:Modeless Vim by svilen_dobrev on Tuesday January 16, 2024 @02:30PM (#39017841)
as said here: https://superuser.com/questions/1716264/xmodmap-holding-a-ke... using this https://github.com/alols/xcape :

  $ setxkbmap -option caps:ctrl_modifier
  $ xcape  -e 'Caps_Lock=Escape'
if that need be run multiple times (i.e. in bashrc), add a guard:

  pgrep xcape >/dev/null || (
   setxkbmap -option caps:ctrl_modifier
   xcape  -e 'Caps_Lock=Escape'
  )
Re:Modeless Vim by joenot443 on Tuesday January 16, 2024 @02:15PM (#39017598)
That sounds awesome! I'm going to look into that.
Re:Modeless Vim by sodapopcan on Tuesday January 16, 2024 @09:23AM (#39013515)
> Ctrl+C

...and to try and avoid this being perpetuated as it always seems to: ctrl-c is NOT the identical to escape. Notably is doesn't trigger InsertLeave which means a handful of plugins won't trigger.

I think your advice can be summed up to: Remap esc to something more convenient. My capslock key is tap for escape and hold for ctrl. I use jk for escaping insert mode because why would I want to be a "victim" who has to stretch their pinky even one key when my fingers are always going to rest on JK? ;)

Re:Modeless Vim by e12e on Tuesday January 16, 2024 @09:24AM (#39013535)
But caps lock is remapped to control already! :)
Re:Modeless Vim by aldanor on Tuesday January 16, 2024 @10:01AM (#39013967)
You can have both. Esc on tap, ctrl on hold.
Re:Modeless Vim by teeray on Tuesday January 16, 2024 @11:35AM (#39015244)
This is the proper functioning for this key
Re:Modeless Vim by e12e on Tuesday January 16, 2024 @05:11PM (#39019877)
On a Mac?
Re:Modeless Vim by bori5 on Tuesday January 16, 2024 @09:45AM (#39013789)
WHAT? HOW AM I GONNA TYPE MY SENTENCES THEN!?
Re:Modeless Vim by arbitrandomuser on Tuesday January 16, 2024 @10:13PM (#39022790)
> WHAT? HOW AM I GONNA TYPE MY SENTENCES THEN!? goto visual mode , select region to capitalize , shift - U
Re:Modeless Vim by crunchbang-excl on Tuesday January 16, 2024 @12:30PM (#39016029)
The caps lock key is definitely using prime real estate on a keyboard for something that doesn't get used often.

I have taken to remapping it to a function key, moving caps lock to function+shift. Function+tab is mapped to escape, a combination I can easily press with my pinky alone.

This allows me to map a lot of the keys that would require moving my hand to function+[alphanumeric key], function+i is insert, function+u is page up, function+j is page down, function+r is home, function+f is end, and other such combinations.

I use a keyboard that supports QMK, so all of this customization is on the keyboard, but this could probably be done with software running on the computer, like AutoHotKey on Windows.

Re:Modeless Vim by JBorrow on Tuesday January 16, 2024 @12:47PM (#39016249)
On a Mac you can do this rebinding entirely natively within the system keyboard settings.
Re:Modeless Vim by dm319 on Tuesday January 16, 2024 @04:04PM (#39019113)
Can I suggest going one further and have esc mapped to tap, ctrl to hold. You can also map double escape to :noh in vim, which allows you to quickly remove highlighting.
Re:Modeless Vim by trws on Tuesday January 16, 2024 @11:21PM (#39023260)
FWIW, my “jk” mapping is also global, as is my C-[ mapping. Karabiner FTW. In all seriousness I haven’t found a way to manage a “jk” mapping that so correctly and quickly handles all cases of input in anything else, on any platform. (Except of course built into the keyboard) Autohotkey can kinda sorta do it, but it takes a lot more code for an inferior result sadly.