Hacker News new | ask | show | jobs
by Nyubis 3911 days ago
Rebinding jk to escape because escape is too far away seemed like a fairly ugly hack to me, especially because you can't type it anymore without waiting.

Why not simply rebind caps lock to escape? Caps lock is used awfully little, considering how prominent its position on the keyboard is. On Linux, you can rebind it by adding

  setxkbmap -option caps:escape
to your .profile. If instead of an additional escape you prefer it to be swapped around, use

  setxkbmap -option caps:swapescape
This is perhaps the most impactful change on my vim workflow.
16 comments

Hi! Author here.

Fair points. I'm gonna start out on the defensive: I didn't post the article, which kinda stinks because if I knew it was going to get such attention I would have updated it to my current setup. Anyways as the 1.5 year old article states:

  This article will almost certainly fall out of date with my vimrc in the very near future
I don't do jk escape anymore. I have since abandoned custom escapes because I work often enough on remote servers with vanilla vimrcs that don't have custom escape bindings set that the penalty I pay having to stop and consider which environment I'm in before every escape wasn't worth the small quality of life enhancement from having it set locally.

Good tip on caps lock, though I currently have it set to control which I find is a much better use of the key. Especially once you know about ctrl-o.

I once told my wife an amusing story I'd read in Australian Personal Computer where a computer technician was told by a secretary that she was great with computers, said technician was very happy and joked that he was glad as the last person he had to help thought that the way to input capital letters was to press the caps lock key, the capital letter and then press the caps lock key again... To which the secretary asked "what's so funny about that?"

Anyway, I chortled after telling this to my wife, to which she looked at me with a puzzled look and asked me what the punchline was...

To be fair, some of the fastest typists use caps lock instead of shift, since it makes the shift action modal, instead of requiring coordination of multiple fingers at once.

http://forum.colemak.com/viewtopic.php?id=1309

Oh! My wife will be pleased :-)
You may wish to look into xcape. Currently i have capslock = escape when pressed alone, or control when pressed with another key. [0] https://github.com/alols/xcape
> Currently i have capslock = escape when pressed alone, or control when pressed with another key.

This is brilliant idea. And it works on OSX too - using http://apple.stackexchange.com/a/132569

Thank you for this! I've been using capslock as Ctrl for a long time time, and fell into the bad habit to use C-c to exit insert mode.
ctrl+] will act as escape in any vim out there. At least that I've encountered.

Having caps as ctrl makes it really easy to hit.

Ctrl-C seems to work in any vim (though, I think, not actual vi), and at some point my muscle memory rewired itself to that. It's usually directly under my left hand, and it's a keyboard shortcut I use elsewhere, like in the shell.
ctrl+[ works in any vim because it sends the exact same character as Escape. Unless your terminal emulator is very oddly configured, then it will work the same.
ctr+[ you mean.
This depends on what you're hosting your article on, but you could either generate the vimrc programatically from the code in the article or generate the article from comments placed in your vimrc. Similar to a .litcoffee file.
Do you think that updating your article would make more sense now. It would benefit users who read it now.
I came across [xcape](https://github.com/alols/xcape) this week. It is a great little utility which can map escape to another key like control or shift but only when pressed once. For example you can configure the control key to be escape if pressed once, but will still act as control if held down. Combined with mapping caps lock to control, I now have the best of all worlds. Highly recommended.
Ack, no. Bind caps lock to Ctrl, and escape is now the trivial chord C-[.

As an added benefit, getting used to this layout will help you out with migrating out of vim to emacs.

yup. i find binding ctrl <-> caps way more useful than binding ctrl to esc (and my keyboard even has a ctrl key made for the caps place and a caps key made for the ctrl position).

BUT there's also a way to do something like: if you press and hold caps, it acts like control. but if you press and release quickly it acts like esc. stevelosh describes how to do that on osx here http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#cont... but i still haven't found a way of doing that on linux.

See link to xcape in this thread.
C-[ is trivial in an English keyboard, but in the Spanish layout it's an awkward three-key chord. I use the latter, and I've been happily inoremapping jj to <esc> for a decade.
So your suggestion is that, rather than pressing Caps Lock to escape, one should press Caps Lock and [? How is that better (assuming you’re using VIM)? Regular Ctrl isn’t hard to reach.
I'm a fan of 'C-c' for escaping.

That keybinding works to go from insert to normal in most filetypes (looking at you sql) without the binding so unconfigured vims are still usable with it, and it's really easy to reach.

I will admit it's a little more awkward than caps-lock, but I use my caps-lock for ctrl and thus can caps-lock-c instead.

Escape isn't really useful anywhere else in the system, so capslock as ctrl or super makes more sense to me.

I agree. If you're on Mac, the tool Seil will allow you to map Caps to Esc. And I use SharpKeys when on Windows.

The downside however is when you're stuck using someone else's computer or don't have root on Mac and Windows. I don't find myself on someone else's machine often though, so for me it's worth it to not have that half second delay.

To add to this, Seil [1] is free and has been available for many years. If anyone here uses it, a donation is probably a good idea.

[1] https://pqrs.org/osx/karabiner/seil.html.en

I use jk, and agree that binding escape to something easy is the most impactful change on my vim workflow.

I encourage everyone to try it. The amount of times in the last year where i've had to actually type the string "jk" is exactly...one? I think, though perhaps I was imagining even that one. I suppose it really doesn't matter what you bind it to as long as you can execute the escape whilst keeping ALL of your fingers on that good ol' home row.

I guess I should also note that I never use vim except in my own environment where i know i have my own vimrc. I totally get why people who are always using remote computers without their vimrc would want to keep default key bindings and thus be forced to use ctrl-[.

I'm another jk devotee, I use caps lock a lot more. I don't get the complaint about using other servers. Either you control them in which case :tabnew ~/.vimrc and adding imap jk <Esc> takes a few seconds, or you don't control them and so you just run the map command locally for your current file. My vimrc is around 200 lines but the jk bind is the only thing I must have these days. Enough forced Eclipse has beat it out of me, but I once had the habit of typing jk outside vim while thinking.
> [...] especially because you can't type it anymore without waiting

This was my thought when I saw this mapping for the first time, and when I started customizing my vimrc I opted for using caps lock as well. It didn´t take long for me to change that and start using kj instead -- in the end it was more common for me to type constants in all-caps than typing "Reykjavik."

I use 'jf' instead of 'jk', so I can type "Dijkstra" occasionally, not to mention they're both on the home row, under your index fingers, typically have physical nubs on the keys, and no words in any language I can find contain the letters 'jf'.
What about IKEA names?
That's when I switch over to emacs and ikea-mode.
Did you know that IKEA names tend to be names of towns and places in Sweden/Norway? So if IKEA names have jf then Swedish/Norwegian must have that letter combo as well..
IKEA also frequently use first names (for people), e.g. Billy or Erik, and even abstract words, e.g. Poäng (point, as in "that's a good point".).

As for jf: I searched through the pdf of a 1300 page Norwegian dictionary, and the single word in there containing jf is the abbreviation "jfr." which is the same as the abbreviation "cf." (confer) in English. So jf appears to be a very good choice.

Note that in Norwegian (and, I think, Swedish and Danish) words are joined without a hypen. So anythime a word ending with "j" like "marsj" ("march/marching") is joined with a word beginning with "f" like "fart" ("speed") you'll see "jf": "marsjfart" ("marching speed"/"cruis(e|ing) speed").

Also jfr isn't a particularly rare abbreviations - so ymmv. At any rate, with how words can be combined in Norwegian, there's generally no good safe choice...

Another example, in line with the IKEA theme: "dusjforheng" ("shower curtain").

Ah, hadn't thought of that. I had a feeling there had to be more words, but couldn't come up with any off the top of my head. Apparently I write very little Norwegian in vim (I use jk for Esc).
As someone else pointed out, caps lock is an excellent compose key, that opens up a world of new characters that can be used throughout the environment.
I set jk to Esc, and not CapsLock, because I use CapsLock to capitalize.

I'm currently working on a vimrc that caters to people like me, those who only use CapsLock to capitalize, and avoid all chording. When I'm done, maybe I can map Shift to Esc.

Ironically, since installing the 'youcompleteme' add on, I've started using the 'jk' escape method more, since ctrl-[ and escape only close the autocomplete window, not out of insert mode.
Here's what works for me:

capslock remapped to ctrl jw for escape in vim

jw is convenient if capslock is used as a control key. I had to pay attention to what I was doing in a vim file in order to remember what I had escape mapped to :)

I've tried remapping Caps Lock, but I find that the stretch to hit that key eventually irritates my ulnar nerve. I'll stick with "jk" (or "ii" on Colemak).
Instead of remapping keys, I've always used Ctrl-[ for escape.
Same here, and I don't even understand why people want to remap Ctrl to Caps (but I never used Mac, so I don't know: maybe it is inconvenient on their keyboards). And recommendation to remap "jk" to Esc always almost made me ignore the whole post, because being able to enter any letter sequence I want is the very least I would expect from a goddamn text editor.
I find pushing ctrl to be at an extremely inconveninet position. Do you look at the keyboard when you type? If so it might explain it. Being a touch typist my left pinky is 1 character away from Capslock so it's way easier to press.
No, I generally don't. But thinking of it, I don't know where my pinky usually is. I mean, I don't always keep it on "a": after all, I have to press Shift pretty often anyway. And Ctrl is pretty close: I don't even need to move my finger to put fingertip on Ctrl, I just use side of the finger to push it.

I tried to use Caps Lock instead of Ctrl, and it wasn't uncomfortable or anything, I just didn't get used to it. I don't remember how it happened that I started to use Ctrl again: maybe it's because I don't always use 1 computer and Ctrl is too important of a key to be looking for every time I need it on somebody else's keyboard. Anyways, currently Caps is Caps and I don't really use it often. Or maybe even ever.

I never need to type "jk" unless I'm pasting a certificate or a hash/UUID/key. It's worth the remap for me. As always, to each his own.
Capslock is already in use as my Compose key.