Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Mapping jk and kj to escape and mapping caps lock to some other hyper key is way better than caps lock to esc IMO. You can just mash both j and k together and you are out of it.

inoremap jk <esc>

And

inoremap kj <esc>

In your vimrc file should do it.



I have considered such alternatives in the past and they did not work for me. For example, how can I conveniently type the string "jk" or "kj" with such a configuration?

The artificial delay I have to introduce between typing "j" and "k" to actually type "jk" is unacceptable. Although it is rare, I sometimes do have to type "jk" in special circumstances such as while typing LaTeX code.

Mapping Caps Lock to Escape is just a much cleaner solution that does not come with any surprises.


Another approach is using 'jj'.

> The artificial delay I have to introduce between typing "j" and "k" to actually type "jk" is unacceptable.

I tried the CAPS approach and tried using it via my left pinky, but find it too awkward to use - but this is probably a very individual thing and it's good that Vim supports it via its remapping capabilities.

But I hear you, sometimes if I have to type the string "jj" I get really confused, but this happens not very often.


I go with system wide caps lock as esc also.... it's how I think of "esc" now in any program not just vim

I also bind ALT-J and ALT-K globally to down and up arrows which is super useful when any kind of drop downs turn up and you want to select different options

I also don't use VIM the program that often, more often than not I'm using Vim bindings in other editors. Though they all have their quirks in terms of what they support.


Alternatively, map caps lock to control and use Ctrl-C or Ctrl-[ instead of escape. That way, you can also easily type any other Ctrl+whatever shortcut too, which IMHO is a bigger win than just escape, especially when Ctrl-[ is so super easy to type then.


I use the 'jk' and 'kj' mapping for escape as well, though I've never actually needed to type those characters out myself or at least it's so rare I don't remember. However, everyone is different.

What I'd suggest if you want to give it a try is to also set the `timeoutlen` to a lower value. By default it's usually 1000ms, but that can be dropped quite a bit I believe without much interference.

    autocmd InsertEnter * set timeoutlen=100
    autocmd InsertLeave * set timeoutlen=1000


This 'jk' and 'kj' mapping works only to get out of the Insert mode. But it does not match the full capability of the original 'Escape'.

- How do you escape from visual mode to normal mode?

- How do you ensure that your abbreviation gets expanded when you escape from insert mode to normal mode?

- How do you escape from operator-pending mode to normal mode? With this mapping, if you press 'd' to delete something and then change your mind and decide to return to normal mode, you are forced to use the original 'Escape' anyway. If you happen to press 'jk' due to habit at this time, it is going to end up deleting lines.

For these reasons, I thought to have a clean mapping of another convenient key (such as Caps Lock) to Escape at an operating system level, rather than trying to make Vim treat some other key as Escape in certain modes.


I have had to type jk or kj very rarely that the egronomics of not having to move my pinky to the caps lock key every time that I need to escape is way worth the extremely minor problem of having to wait a second when I need to type jk. Optimize for the common and handle the exeptional.


The inoremap jk <esc>, inoremap kj <esc> configuration gets you back to normal mode only from insert mode. What do you do if you want to return to normal mode from visual mode or command mode?

What if you want to type an abbreviation and expand it when you escape from insert mode to normal mode?


> What if you want to type an abbreviation and expand it when you escape from insert mode to normal mode?

I press space or tab or enter or actual escape if I need an abbreviation and it happens to be at the end of what I intended to insert... I pretty much never rely on escape to do the abbreviations though because it's not at the end of what I want to insert anyway.

I also don't use visual mode enough to need to have an escape for it. you can certainly change the timeout on visual mode and add a visual mode mapping for that too if you want to do that. It seems you have a the attitude of this is the only "correct" way to do it. I don't really care if you use it or not... I was merely providing an alternative way to do what you want with the added benefit of it giving you an extra modifier key that you can bind other things to. You can also map it globally or for each of the handful of modes you want to escape from using it.


This configuration is commonly known as "lol jk".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: