Remapping Caps-Lock to Escape

25 views
Skip to first unread message

tom

unread,
Jun 13, 2008, 9:27:59 PM6/13/08
to vim_mac
I'm using Leopard + MacVim, and I'm really accustomed to using caps-
lock as escape (in Linux). Is there some way to pull this off using
the map or map! command? I see it used for tons of other stuff, but
not this, unfortunately. Is this doable? I've seen the macosxhints
article on this, but I'd really like to avoid Keyboard Maestro, since
this computer is temporary and I don't want to pay the shareware fee.
Is there a way to do this? If it's only remapped in vim, then I'm
happy.

Thanks!

Tom

Timothy Grant

unread,
Jun 13, 2008, 10:25:27 PM6/13/08
to vim...@googlegroups.com
I've heard of lots of people using it as Control, but never as Esc. (I remap mine as Control). I'm not sure if you know this but Ctrl + ] = Esc.




--
Stand Fast,
tjg.

Ben Schmidt

unread,
Jun 14, 2008, 12:05:33 AM6/14/08
to vim...@googlegroups.com
Timothy Grant wrote:
> On Fri, Jun 13, 2008 at 6:27 PM, tom <macw...@gmail.com
> <mailto:macw...@gmail.com>> wrote:
>
>
> I'm using Leopard + MacVim, and I'm really accustomed to using caps-
> lock as escape (in Linux). Is there some way to pull this off using
> the map or map! command? I see it used for tons of other stuff, but
> not this, unfortunately. Is this doable? I've seen the macosxhints
> article on this, but I'd really like to avoid Keyboard Maestro, since
> this computer is temporary and I don't want to pay the shareware fee.
> Is there a way to do this? If it's only remapped in vim, then I'm
> happy.

It can't be done with :map and friends.

I think there is some kernel hack (well, hey, almost all varieties
of this kind of thing are kernel hacks--some are just dirtier than
others) that can do this...let me spot the link...

OK...I can spot three...

http://www.gnufoo.org/ucontrol/
http://www.kodachi.com/software/fKeys/about.html
http://doublecommand.sourceforge.net/

None look all that promising. :-\ But perhaps getting in touch with the
developers of DoubleCommand, which seems to be the only one still being
developed, might yield some results. It doesn't address your particular
request, but perhaps they can easily add it. Please do post back here if
you discover anything!

Ben.

tom

unread,
Jun 14, 2008, 2:22:48 AM6/14/08
to vim_mac
Geez, bummer. So everyone using vim on a mac is either stretching to
the esc key or is doing a chord to switch modes? I must say, I'm
pretty disappointed.

On Jun 14, 12:05 am, Ben Schmidt <mail_ben_schm...@yahoo.com.au>
wrote:
> Timothy Grant wrote:
> > On Fri, Jun 13, 2008 at 6:27 PM, tom <macwri...@gmail.com
> > <mailto:macwri...@gmail.com>> wrote:
>
> > I'm using Leopard + MacVim, and I'm really accustomed to using caps-
> > lock as escape (in Linux). Is there some way to pull this off using
> > the map or map! command? I see it used for tons of other stuff, but
> > not this, unfortunately. Is this doable? I've seen the macosxhints
> > article on this, but I'd really like to avoid Keyboard Maestro, since
> > this computer is temporary and I don't want to pay the shareware fee.
> > Is there a way to do this? If it's only remapped in vim, then I'm
> > happy.
>
> It can't be done with :map and friends.
>
> I think there is some kernel hack (well, hey, almost all varieties
> of this kind of thing are kernel hacks--some are just dirtier than
> others) that can do this...let me spot the link...
>
> OK...I can spot three...
>
> http://www.gnufoo.org/ucontrol/http://www.kodachi.com/software/fKeys/about.htmlhttp://doublecommand.sourceforge.net/

Morel David

unread,
Jun 14, 2008, 2:27:58 AM6/14/08
to vim...@googlegroups.com

Le 14 juin 08 à 08:22, tom a écrit :

>
> Geez, bummer. So everyone using vim on a mac is either stretching to
> the esc key or is doing a chord to switch modes? I must say, I'm
> pretty disappointed.

This is the week-end. troll mode is off on week-ends. Come back on
Monday.

Thanks !

David

Ben Schmidt

unread,
Jun 14, 2008, 2:44:26 AM6/14/08
to vim...@googlegroups.com
tom wrote:
> Geez, bummer. So everyone using vim on a mac is either stretching to
> the esc key or is doing a chord to switch modes?

I think most people are. I don't find escape hard to get to. I do find
Ctrl hard to get to (well, more the contortions needed to use it in
combination with other keys), so have Caps Lock mapped to that.

> I must say, I'm pretty disappointed.

It is a little bit of a shame.

There are other alternatives out there, though. Here are some I've
heard:

- Map <Tab> or ` to <Esc>. A little closer than the <Esc> key. Though
losing <Tab> would be disastrous for me!
- Map <F1> and other nearby keys to <Esc> so you only have to jab vaguely
in the right direction and you'll get it.
- Use gvim in X11 where remapping stuff is possible, I believe. (I don't
think many do this, though.)
- Map jj or ,, to <Esc> in insert mode, since these don't occur in
ordinary text. I think I'd probably find jk easier, and I can't think
of any text *I* write where that occurs... Still, so far, I'm happy
with <Esc>!

Maybe you'd be interested to try one of those approaches. It's different
to what you were hoping, but may turn out just as good.

Ben.

dv1...@wayne.edu

unread,
Jun 14, 2008, 11:03:16 AM6/14/08
to vim...@googlegroups.com
Thus spake Ben Schmidt [06/14/08 @ 16.44.26 +1000]:

> tom wrote:
> > Geez, bummer. So everyone using vim on a mac is either stretching to
> > the esc key or is doing a chord to switch modes?
>
> I think most people are. I don't find escape hard to get to. I do find
> Ctrl hard to get to (well, more the contortions needed to use it in
> combination with other keys), so have Caps Lock mapped to that.
>
> > I must say, I'm pretty disappointed.
>
> It is a little bit of a shame.
>
> There are other alternatives out there, though. Here are some I've
> heard:
>
> - Map <Tab> or ` to <Esc>. A little closer than the <Esc> key. Though
> losing <Tab> would be disastrous for me!
> - Map <F1> and other nearby keys to <Esc> so you only have to jab vaguely
> in the right direction and you'll get it.
> - Use gvim in X11 where remapping stuff is possible, I believe. (I don't
> think many do this, though.)
> - Map jj or ,, to <Esc> in insert mode, since these don't occur in
> ordinary text. I think I'd probably find jk easier, and I can't think
> of any text *I* write where that occurs... Still, so far, I'm happy
> with <Esc>!

I use a chord, but it's a really easy chord: I map CapsLock to Ctrl, and in my .vimrc map <C-Space> to <Esc>. My thumbs are hovering over the space bar anyway, so to do that chord with pinky and thumb is really quick. Another equally quick alternative is to use 'j' instead of Space. With either of those, the chordness of the chord is not a problem.
-gmn

Nikola Knežević

unread,
Jun 14, 2008, 1:08:11 PM6/14/08
to vim...@googlegroups.com
On 14 Jun 2008, at 03:27 , tom wrote:
> article on this, but I'd really like to avoid Keyboard Maestro, since
> this computer is temporary and I don't want to pay the shareware fee.
> Is there a way to do this? If it's only remapped in vim, then I'm
> happy.

There is this utility:
http://www.pqrs.org/tekezo/macosx/keyremap4macbook/

Takezo is more then willing to add any required feature.

Cheers,
Nikola

Morel David

unread,
Jun 14, 2008, 1:15:42 PM6/14/08
to vim...@googlegroups.com
Le 14 juin 08 à 06:05, Ben Schmidt a écrit :

>
> Timothy Grant wrote:
>> On Fri, Jun 13, 2008 at 6:27 PM, tom <macw...@gmail.com
>> <mailto:macw...@gmail.com>> wrote:
>>
>>
>> I'm using Leopard + MacVim, and I'm really accustomed to using
>> caps-
>> lock as escape (in Linux). Is there some way to pull this off
>> using
>> the map or map! command? I see it used for tons of other stuff,
>> but
>> not this, unfortunately. Is this doable? I've seen the macosxhints
>> article on this, but I'd really like to avoid Keyboard Maestro,
>> since
>> this computer is temporary and I don't want to pay the shareware
>> fee.
>> Is there a way to do this? If it's only remapped in vim, then I'm
>> happy.
>

> http://doublecommand.sourceforge.net/
>
> None look all that promising. :-\ But perhaps getting in touch with
> the
> developers of DoubleCommand, which seems to be the only one still
> being
> developed, might yield some results. It doesn't address your
> particular
> request, but perhaps they can easily add it. Please do post back
> here if
> you discover anything!

I dowloaded the source for double command (1.6.6b4) and added a #define
ESC_KEY 53 in Common.h, and used that instead of DELETE in
Substitute.cpp (line 925). This is very ugly since this is activated by
'Caps lock key acts as delete key' line in the pref pane, but go me a
working .kext in 5 minutes. So it's very easy to do :)

You probably want to mail the Doublecommand people, they would probably
do it -but cleanly- in 5 minutes as well. ;)

David


Ted Pavlic

unread,
Jun 15, 2008, 10:46:13 AM6/15/08
to vim_mac
This link looks promising, but I didn't see a script for the Escape
character, so it may not be helpful.

http://lifehacker.com/software/autohotkey-answers/turn-your-capslock-key-into-a-dedicated-minimize-button-317239.php

However, because it is a hotkey scripting language, you have to imagine
that something is possible. For example, the

Send / SendRaw / SendInput / SendPlay

set of commands "Sends simulated keystrokes and mouse clicks to the
active window."

--Ted

--
Ted Pavlic <t...@tedpavlic.com>

Fredrik Bränström

unread,
Jun 15, 2008, 3:05:07 PM6/15/08
to vim_mac
This is the one that solved it for me. The Mac and vim in perfect
blissful harmony - esc on its throne, where it belongs; just to the
left of my pinky. :)

Fredrik Bränström

unread,
Jun 15, 2008, 3:07:08 PM6/15/08
to vim_mac
Oh, and contrary to what the name suggests, this utility works on more
than MacBooks. At least the Apple Wireless keyboard that came with my
iMac (alu, 2007) is hackable with it...

On Jun 14, 7:08 pm, Nikola Knežević <laladelausa...@gmail.com> wrote:

Timothy Grant

unread,
Jun 15, 2008, 3:54:58 PM6/15/08
to vim...@googlegroups.com
2008/6/15 Fredrik Bränström <bran...@gmail.com>:
I'm honestly curious about this. I would have thought CTRL was used far more often than ESC.

--
Stand Fast,
tjg.

dacresni

unread,
Jun 15, 2008, 8:57:09 PM6/15/08
to vim_mac
anyone here uses the ball of their pinky to press escape? ps. there's
a plist that alters which keys do what, you're not in X so this
manages the key-bindings ~/Library/KeyBindings/DefaultKeyBinding.dict
there will be a little research involved but at least you can't blame
anyone else for screwing things up.

Ted Pavlic

unread,
Jun 16, 2008, 1:10:45 PM6/16/08
to vim_mac
Fredrik --

Can you explain how?

I can find ways to remap Function, Shift, and Tab, but not to remap
Caps Lock. Have you remapped your caps lock to escape? Or are you
talking about one of the other keys?

Thanks --
Ted

(note: one day, I remapped caps lock to control through some other
mechanism, but I forgot how... I'm sure it involved modifying some pref
somewhere)

--
Ted Pavlic <t...@tedpavlic.com>

Ted Pavlic

unread,
Jun 16, 2008, 1:16:29 PM6/16/08
to vim_mac
That's what I get for suggesting something I hadn't tried.

The Google search that led me there was highly Mac biased. However, for
some reason this link came up. AutoHotkey is a Windows app. :(

Sorry. :(

--Ted

Tim Hammerquist

unread,
Jun 16, 2008, 5:08:37 PM6/16/08
to vim...@googlegroups.com
I also use the <C-[> chord to simulate <Esc>.  (<C-]> is for tag jumping.)  In <=10.4 I used a kernel hack utility to enable this (uControl, iirc), but in Leopard there is a dialog in the "Keyboard & Mouse" prefpane.

Select "System Preferences", "Keyboard & Mouse", "Keyboard" tab, and click "Modifier Keys..." at the bottom-right. In this window you can map <Ctrl>, <CapsLock>, <Option>, and <Command> to each other (or a NOOP).

As I've had years of using <C-[> this is good for me, and may help others who use this chord to weed out third-party hacks on their system.  On the upside, xmodmap will remap <CapsLock> to <Ctrl> as well. :)

HTH,
Tim

Tim Hammerquist

unread,
Jun 16, 2008, 5:09:39 PM6/16/08
to vim...@googlegroups.com
Select "System Preferences", "Keyboard & Mouse", "Keyboard" tab, and click "Modifier Keys..." at the bottom-right. In this window you can map <Ctrl>, <CapsLock>, <Option>, and <Command> to each other (or a NOOP).

That button is in the bottom-LEFT.  Apologies.

Tim

tom

unread,
Jun 16, 2008, 6:46:01 PM6/16/08
to vim_mac
Hey, sorry I haven't responded in a little bit. I tried out
DoubleCommand and wasn't very impressed, but PCKeyboardHack (despite
the scary name) does the trick perfectly:
http://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html

David Wilhelm

unread,
Jul 13, 2009, 12:51:04 PM7/13/09
to vim...@googlegroups.com
This worked for my macbook

http://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html

i also installed his KeyRemap4MacBook, though I'm not sure if that's
necessary. These apps put a nice config gui in your Preferences panel,
and you can easily uninstall at any time which is nice. The only side-
effect is that the LED on my caps lock is lit up , but you get used to
it.

Dave

björn

unread,
Jul 13, 2009, 1:34:09 PM7/13/09
to vim...@googlegroups.com
2009/7/13 David Wilhelm:

>
> This worked for my macbook
>
> http://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html
>
> i also installed his KeyRemap4MacBook, though I'm not sure if that's
> necessary. These apps put a nice config gui in your Preferences panel,
> and you can easily uninstall at any time which is nice. The only side-
> effect is that the LED on my caps lock is lit up , but you get used to
> it.

The trick is to go into System Preferences -> Keyboard and Mouse ->
Keyboard (tab) -> Modifiers Keys... (button). Then change the "Caps
Lock" drop down menu to read "^ Control" and then go into the
PCKeyboardHack pref and remap Caps Lock to keycode 53 (Escape).

There, no more Caps Lock lighting up (and before I did this Caps Lock
presses sometimes used to fail to register).

Björn

Reply all
Reply to author
Forward
0 new messages