Loading ...
Sorry, an error occurred while loading the content.

Re: Patch to turn Caps-Lock into Esc

Expand Messages
  • Alex Esplin
    ... I have the following in my .vimrc and it works just fine: map escape to F3 map map! -- Alex Esplin
    Message 1 of 14 , Oct 1, 2008
    • 0 Attachment
      On Wed, Oct 1, 2008 at 4:09 PM, björn <bjorn.winckler@...> wrote:
      > I guess it would require some hacking in the source code to remap Esc.
      > I haven't got any great ideas how best to do this at the moment, but
      > I'll give it some thought. At first thought it seems like it would
      > have to be done when the input is received inside MacVim and not
      > inside Vim.

      I have the following in my .vimrc and it works just fine:

      "map escape to F3
      map <F3> <Esc>
      map! <F3> <Esc>


      --
      Alex Esplin

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Britt Selvitelle
      It seems this has made its way into HEAD! Is this worth of a pref in the UI? ... --~--~---------~--~----~------------~-------~--~----~ You received this
      Message 2 of 14 , Oct 23, 2008
      • 0 Attachment
        It seems this has made its way into HEAD!
        Is this worth of a pref in the UI?

        On Sep 30, 1:37 pm, "björn" <bjorn.winck...@...> wrote:
        > Hi all,
        >
        > The possibility to remap Caps-Lock to function as a second Escape key
        > has been brought up before.  I never thought about this much before,
        > but being able to use Caps-Lock as Esc really makes a whole lot of
        > sense so I decided to see what could be done about this.
        >
        > It turns out that Mac OS X lets you remap Caps-Lock to function as
        > Ctrl, Alt, or Cmd, which is useful for Emacs I guess, but not so much
        > with Vim.  But that got me thinking: maybe the Caps-Lock key can still
        > be identified by some virtual key code.  If so, I could remap
        > Caps-Lock to Ctrl (for instance) and then check when Ctrl was pressed
        > if the actual key pressed really was Caps-Lock.  Unfortunately I
        > couldn't figure out a way to do this (Caps-Lock sends the same key
        > code as the modifier you remap it to), so I had to hack it a bit.
        >
        > The attached patch will let you turn one of the _left_ modifier keys
        > into a sort of pseudo-Esc key: the modifier will work as usual, unless
        > it is pressed and released quickly (with no intervening key presses)
        > in which case it sends an Esc key event.  I use it as follows: first I
        > go into the System Preferences and remap Caps-Lock to Ctrl.  Then I
        > can happily use Caps-Lock as Esc but also as a Ctrl key (useful for
        > Ctrl-f, etc.).
        >
        > The only downside I've noticed so far is that Caps-Lock feels somewhat
        > sluggish as Esc, since the Esc event is sent when you release
        > Caps-Lock.  If this bothers anybody I've added an option to send the
        > Esc event on key down but that will effectively disable the chosen
        > modifier key.  However, it only turns the _left_ modifier key into
        > Esc.  So, it is possible to e.g. remap Caps-Lock to Alt and then use
        > the _right_ Alt as a normal Alt key (I have two Alt keys, but only one
        > Ctrl on my keyboard, and I rarely use Alt anyway).  I'm not sure
        > anybody wants to do this...I think I may use it myself if the
        > sluggishness bothers me (otherwise I'll stick with Caps-Lock as Ctrl).
        >
        > To use:
        >
        > 1. Apply patch and recompile
        > 2. Enter "System Preferences -> Keyboard & Mouse -> Modifier Keys..."
        > and remap Caps-Lock to Ctrl
        > 3. Open Terminal and type (one line): defaults write org.vim.MacVim
        > MMFakeEscModifier 1
        > 4. Start MacVim and use Caps-Lock as Escape/Ctrl!
        >
        > If you want to use another modifier key, or if you want Caps-Lock to
        > send Esc on key down, then read the commit message:
        >
        >     Modifier key sends Esc
        >
        >     Adds possibility to make the left Ctrl, Alt, or Cmd key function as a
        >     second Esc key.  The key will still function as a modifier if held down
        >     in conjunction with another key.  Enable by setting the user default
        >     "MMFakeEscModifier" to:
        >         1 = Left Ctrl
        >         2 = Left Alt
        >         3 = Left Cmd
        >         any other number disables this functionality
        >
        >     By remapping Caps-Lock to one of the above modifier keys this enables
        >     the use of Caps-Lock as a second (and easy to reach) Esc key.  Caps-Lock
        >     can be remapped inside "System Preferences -> Keyboard & Mouse ->
        >     Modifier Keys...".
        >
        >     The Esc event is send when the modifier key is released.  If the key is
        >     not released within a predefined timeout, then no Esc event is
        >     generated.  The timeout can be changed by setting the user default
        >     MMFakeEscTimeout (a float, specifying the timeout in seconds).
        >
        >     The fact that the Esc event is sent on release makes it feel somewhat
        >     sluggish.  It is possible to have the event sent when the modifier key
        >     is pressed by setting the user default "MMFakeEscOnKeyDown" but then the
        >     left modifier key can only be used as an Esc key.
        >
        > Let me know what you think about the patch.
        >
        > Björn
        >
        >  0001-Modifier-key-sends-Esc.patch
        > 11KViewDownload

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_mac" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Fredrik Bränström
        Just as I and Tom mention in this thread
        Message 3 of 14 , Oct 25, 2008
        • 0 Attachment
          Just as I and Tom mention in this thread
          http://groups.google.com/group/vim_mac/browse_thread/thread/b7fbb421fb38f613/0794146b93bfbb8c?lnk=gst&q=remapping+caps#0794146b93bfbb8c,
          the KeyRemap4MacBook prefpane together with the PCKeyboard Hack
          prefpane, available at http://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html
          will reliably transform your caps lock key into an escape key.

          It can remap lots of other keys as well. But this is pretty much all I
          use it for. :) Let me quote myself:

          Fredrik Bränström wrote:
          > 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. :)

          On Oct 23, 11:01 pm, Britt Selvitelle <anotherbr...@...> wrote:
          > It seems this has made its way into HEAD!
          > Is this worth of a pref in the UI?
          >
          > On Sep 30, 1:37 pm, "björn" <bjorn.winck...@...> wrote:
          >
          > > Hi all,
          >
          > > The possibility to remap Caps-Lock to function as a second Escape key
          > > has been brought up before.  I never thought about this much before,
          > > but being able to use Caps-Lock as Esc really makes a whole lot of
          > > sense so I decided to see what could be done about this.
          >
          > > It turns out that Mac OS X lets you remap Caps-Lock to function as
          > > Ctrl, Alt, or Cmd, which is useful for Emacs I guess, but not so much
          > > with Vim.  But that got me thinking: maybe the Caps-Lock key can still
          > > be identified by some virtual key code.  If so, I could remap
          > > Caps-Lock to Ctrl (for instance) and then check when Ctrl was pressed
          > > if the actual key pressed really was Caps-Lock.  Unfortunately I
          > > couldn't figure out a way to do this (Caps-Lock sends the same key
          > > code as the modifier you remap it to), so I had to hack it a bit.
          >
          > > The attached patch will let you turn one of the _left_ modifier keys
          > > into a sort of pseudo-Esc key: the modifier will work as usual, unless
          > > it is pressed and released quickly (with no intervening key presses)
          > > in which case it sends an Esc key event.  I use it as follows: first I
          > > go into the System Preferences and remap Caps-Lock to Ctrl.  Then I
          > > can happily use Caps-Lock as Esc but also as a Ctrl key (useful for
          > > Ctrl-f, etc.).
          >
          > > The only downside I've noticed so far is that Caps-Lock feels somewhat
          > > sluggish as Esc, since the Esc event is sent when you release
          > > Caps-Lock.  If this bothers anybody I've added an option to send the
          > > Esc event on key down but that will effectively disable the chosen
          > > modifier key.  However, it only turns the _left_ modifier key into
          > > Esc.  So, it is possible to e.g. remap Caps-Lock to Alt and then use
          > > the _right_ Alt as a normal Alt key (I have two Alt keys, but only one
          > > Ctrl on my keyboard, and I rarely use Alt anyway).  I'm not sure
          > > anybody wants to do this...I think I may use it myself if the
          > > sluggishness bothers me (otherwise I'll stick with Caps-Lock as Ctrl).
          >
          > > To use:
          >
          > > 1. Apply patch and recompile
          > > 2. Enter "System Preferences -> Keyboard & Mouse -> Modifier Keys..."
          > > and remap Caps-Lock to Ctrl
          > > 3. Open Terminal and type (one line): defaults write org.vim.MacVim
          > > MMFakeEscModifier 1
          > > 4. Start MacVim and use Caps-Lock as Escape/Ctrl!
          >
          > > If you want to use another modifier key, or if you want Caps-Lock to
          > > send Esc on key down, then read the commit message:
          >
          > >     Modifier key sends Esc
          >
          > >     Adds possibility to make the left Ctrl, Alt, or Cmd key function as a
          > >     second Esc key.  The key will still function as a modifier if held down
          > >     in conjunction with another key.  Enable by setting the user default
          > >     "MMFakeEscModifier" to:
          > >         1 = Left Ctrl
          > >         2 = Left Alt
          > >         3 = Left Cmd
          > >         any other number disables this functionality
          >
          > >     By remapping Caps-Lock to one of the above modifier keys this enables
          > >     the use of Caps-Lock as a second (and easy to reach) Esc key.  Caps-Lock
          > >     can be remapped inside "System Preferences -> Keyboard & Mouse ->
          > >     Modifier Keys...".
          >
          > >     The Esc event is send when the modifier key is released.  If the key is
          > >     not released within a predefined timeout, then no Esc event is
          > >     generated.  The timeout can be changed by setting the user default
          > >     MMFakeEscTimeout (a float, specifying the timeout in seconds).
          >
          > >     The fact that the Esc event is sent on release makes it feel somewhat
          > >     sluggish.  It is possible to have the event sent when the modifier key
          > >     is pressed by setting the user default "MMFakeEscOnKeyDown" but then the
          > >     left modifier key can only be used as an Esc key.
          >
          > > Let me know what you think about the patch.
          >
          > > Björn
          >
          > >  0001-Modifier-key-sends-Esc.patch
          > > 11KViewDownload
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_mac" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Fredrik Bränström
          Oh, and very importantly, it s free of sluggishness - void of any delay in the activation, despite this being the magic caps lock key of the wireless Apple
          Message 4 of 14 , Oct 25, 2008
          • 0 Attachment
            Oh, and very importantly, it's free of sluggishness - void of any
            delay in the activation, despite this being the "magic" caps lock key
            of the wireless Apple keyboard that I'm using...

            On Oct 25, 11:14 am, Fredrik Bränström <branst...@...> wrote:
            > Just as I and Tom mention in this threadhttp://groups.google.com/group/vim_mac/browse_thread/thread/b7fbb421f...,
            > the KeyRemap4MacBook prefpane together with the PCKeyboard Hack
            > prefpane, available athttp://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html
            > will reliably transform your caps lock key into an escape key.
            >
            > It can remap lots of other keys as well. But this is pretty much all I
            > use it for. :) Let me quote myself:
            >
            > Fredrik Bränström wrote:
            > > 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. :)
            >
            > On Oct 23, 11:01 pm, Britt Selvitelle <anotherbr...@...> wrote:
            >
            > > It seems this has made its way into HEAD!
            > > Is this worth of a pref in the UI?
            >
            > > On Sep 30, 1:37 pm, "björn" <bjorn.winck...@...> wrote:
            >
            > > > Hi all,
            >
            > > > The possibility to remap Caps-Lock to function as a second Escape key
            > > > has been brought up before.  I never thought about this much before,
            > > > but being able to use Caps-Lock as Esc really makes a whole lot of
            > > > sense so I decided to see what could be done about this.
            >
            > > > It turns out that Mac OS X lets you remap Caps-Lock to function as
            > > > Ctrl, Alt, or Cmd, which is useful for Emacs I guess, but not so much
            > > > with Vim.  But that got me thinking: maybe the Caps-Lock key can still
            > > > be identified by some virtual key code.  If so, I could remap
            > > > Caps-Lock to Ctrl (for instance) and then check when Ctrl was pressed
            > > > if the actual key pressed really was Caps-Lock.  Unfortunately I
            > > > couldn't figure out a way to do this (Caps-Lock sends the same key
            > > > code as the modifier you remap it to), so I had to hack it a bit.
            >
            > > > The attached patch will let you turn one of the _left_ modifier keys
            > > > into a sort of pseudo-Esc key: the modifier will work as usual, unless
            > > > it is pressed and released quickly (with no intervening key presses)
            > > > in which case it sends an Esc key event.  I use it as follows: first I
            > > > go into the System Preferences and remap Caps-Lock to Ctrl.  Then I
            > > > can happily use Caps-Lock as Esc but also as a Ctrl key (useful for
            > > > Ctrl-f, etc.).
            >
            > > > The only downside I've noticed so far is that Caps-Lock feels somewhat
            > > > sluggish as Esc, since the Esc event is sent when you release
            > > > Caps-Lock.  If this bothers anybody I've added an option to send the
            > > > Esc event on key down but that will effectively disable the chosen
            > > > modifier key.  However, it only turns the _left_ modifier key into
            > > > Esc.  So, it is possible to e.g. remap Caps-Lock to Alt and then use
            > > > the _right_ Alt as a normal Alt key (I have two Alt keys, but only one
            > > > Ctrl on my keyboard, and I rarely use Alt anyway).  I'm not sure
            > > > anybody wants to do this...I think I may use it myself if the
            > > > sluggishness bothers me (otherwise I'll stick with Caps-Lock as Ctrl).
            >
            > > > To use:
            >
            > > > 1. Apply patch and recompile
            > > > 2. Enter "System Preferences -> Keyboard & Mouse -> Modifier Keys..."
            > > > and remap Caps-Lock to Ctrl
            > > > 3. Open Terminal and type (one line): defaults write org.vim.MacVim
            > > > MMFakeEscModifier 1
            > > > 4. Start MacVim and use Caps-Lock as Escape/Ctrl!
            >
            > > > If you want to use another modifier key, or if you want Caps-Lock to
            > > > send Esc on key down, then read the commit message:
            >
            > > >     Modifier key sends Esc
            >
            > > >     Adds possibility to make the left Ctrl, Alt, or Cmd key function as a
            > > >     second Esc key.  The key will still function as a modifier if held down
            > > >     in conjunction with another key.  Enable by setting the user default
            > > >     "MMFakeEscModifier" to:
            > > >         1 = Left Ctrl
            > > >         2 = Left Alt
            > > >         3 = Left Cmd
            > > >         any other number disables this functionality
            >
            > > >     By remapping Caps-Lock to one of the above modifier keys this enables
            > > >     the use of Caps-Lock as a second (and easy to reach) Esc key.  Caps-Lock
            > > >     can be remapped inside "System Preferences -> Keyboard & Mouse ->
            > > >     Modifier Keys...".
            >
            > > >     The Esc event is send when the modifier key is released.  If the key is
            > > >     not released within a predefined timeout, then no Esc event is
            > > >     generated.  The timeout can be changed by setting the user default
            > > >     MMFakeEscTimeout (a float, specifying the timeout in seconds).
            >
            > > >     The fact that the Esc event is sent on release makes it feel somewhat
            > > >     sluggish.  It is possible to have the event sent when the modifier key
            > > >     is pressed by setting the user default "MMFakeEscOnKeyDown" but then the
            > > >     left modifier key can only be used as an Esc key.
            >
            > > > Let me know what you think about the patch.
            >
            > > > Björn
            >
            > > >  0001-Modifier-key-sends-Esc.patch
            > > > 11KViewDownload
            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_mac" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • björn
            Hi, I do now remember reading Fredrik s original post on this subject but for some reason I forgot about all of this when I wrote the patch. Ted Pavlic also
            Message 5 of 14 , Oct 25, 2008
            • 0 Attachment
              Hi,

              I do now remember reading Fredrik's original post on this subject but
              for some reason I forgot about all of this when I wrote the patch.
              Ted Pavlic also mentioned the pc keyboard hack in another thread on
              this same subject but I must admit that I never got around to checking
              it out at that time.

              Now that I have tried it I can confirm that it works really
              well...with one reservation. I too have the wireless Apple keyboard
              (with the delayed caps-lock) and I found that after remapping
              caps-lock to escape, half the time my key presses did not register.
              However, after going into the "Keyboard&Mouse" system preferences and
              remapping caps-lock to ctrl it all works fine again (i.e. I needed to
              "remap twice"!).

              So, in light of this it seems the patch I wrote is quite useless and I
              will go ahead and deprecate it. I will still have some entry in the
              help file which outlines how to use the pc keyboard hack and I may
              perhaps provide a link on the google code page.

              Thanks to everybody who commented on this patch!

              Björn

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_mac" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Fredrik Bränström
              Hmm. And you re sure you enabled the CapsLock LED hack in KeyRemap4MacBook s General section? It removes the delay for me, and I haven t had any key presses
              Message 6 of 14 , Oct 26, 2008
              • 0 Attachment
                Hmm. And you're sure you enabled the CapsLock LED hack in
                KeyRemap4MacBook's "General" section? It removes the delay for me, and
                I haven't had any key presses go lost in infinity.

                The only side-effect is that the LED is on constantly (off when you're
                idle though).

                On Oct 25, 12:10 pm, "björn" <bjorn.winck...@...> wrote:
                > Hi,
                >
                > I do now remember reading Fredrik's original post on this subject but
                > for some reason I forgot about all of this when I wrote the patch.
                > Ted Pavlic also mentioned the pc keyboard hack in another thread on
                > this same subject but I must admit that I never got around to checking
                > it out at that time.
                >
                > Now that I have tried it I can confirm that it works really
                > well...with one reservation.  I too have the wireless Apple keyboard
                > (with the delayed caps-lock) and I found that after remapping
                > caps-lock to escape, half the time my key presses did not register.
                > However, after going into the "Keyboard&Mouse" system preferences and
                > remapping caps-lock to ctrl it all works fine again (i.e. I needed to
                > "remap twice"!).
                >
                > So, in light of this it seems the patch I wrote is quite useless and I
                > will go ahead and deprecate it.  I will still have some entry in the
                > help file which outlines how to use the pc keyboard hack and I may
                > perhaps provide a link on the google code page.
                >
                > Thanks to everybody who commented on this patch!
                >
                > Björn
                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_mac" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • björn
                ... I only downloaded the PCKeyboardHack program -- the KeyRemap4MacBook did not seem necessary (and indeed PCKeyboardHack works without it). ... This is not
                Message 7 of 14 , Oct 27, 2008
                • 0 Attachment
                  2008/10/27 Fredrik Bränström <branstrom@...>:
                  >
                  > Hmm. And you're sure you enabled the CapsLock LED hack in
                  > KeyRemap4MacBook's "General" section? It removes the delay for me, and
                  > I haven't had any key presses go lost in infinity.

                  I only downloaded the PCKeyboardHack program -- the KeyRemap4MacBook
                  did not seem necessary (and indeed PCKeyboardHack works without it).

                  > The only side-effect is that the LED is on constantly (off when you're
                  > idle though).

                  This is not an issue if you remap Caps Lock to Ctrl first like I
                  did...so I guess all in all this is a better solution in that you only
                  need to download and install one app and then LED never turns on. :-)

                  Björn

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_mac" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Fredrik Bränström
                  That s true! I ve been using esc (at caps) outside vim though... but I might use ctrl more, if I moved it to caps. So... um... yeah. Two solutions available.
                  Message 8 of 14 , Oct 27, 2008
                  • 0 Attachment
                    That's true! I've been using esc (at caps) outside vim though... but I
                    might use ctrl more, if I moved it to caps. So... um... yeah. Two
                    solutions available. Rejoice, all!

                    On Oct 27, 6:18 pm, "björn" <bjorn.winck...@...> wrote:
                    > 2008/10/27 Fredrik Bränström <branst...@...>:
                    >
                    >
                    >
                    > > Hmm. And you're sure you enabled the CapsLock LED hack in
                    > > KeyRemap4MacBook's "General" section? It removes the delay for me, and
                    > > I haven't had any key presses go lost in infinity.
                    >
                    > I only downloaded the PCKeyboardHack program -- the KeyRemap4MacBook
                    > did not seem necessary (and indeed PCKeyboardHack works without it).
                    >
                    > > The only side-effect is that the LED is on constantly (off when you're
                    > > idle though).
                    >
                    > This is not an issue if you remap Caps Lock to Ctrl first like I
                    > did...so I guess all in all this is a better solution in that you only
                    > need to download and install one app and then LED never turns on. :-)
                    >
                    > Björn
                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_mac" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  Your message has been successfully submitted and would be delivered to recipients shortly.