3

I am trying to map Cmd+Alt to start searching in vim (/). The only question is: how would I do this? I know to map Alt in vimscript is by typing <A> but I do not know how to do Cmd.

I also want to press the keys at the same time (not one after the other)

5
  • Are you using MacVim? Or Vim from a terminal? Mar 5, 2015 at 20:23
  • I am using terminal.
    – iProgram
    Mar 5, 2015 at 20:23
  • @MartinTournoij Do you imply by your comment that this is possible in MacVim?
    – Hotschke
    Apr 12, 2020 at 10:52
  • I don't know @Hotschke, I probably added it because it may be possible, and keymapings work quite different technically on the terminal vs. a GUI, so solutions could differ. Apr 12, 2020 at 11:10
  • @MartinTournoij. I see. Thanks for your quick response. I did not find anything in the help page dedicated to MacVim: :h macvim. I guess Karabiner Elements could help here by mapping Cmd+Alt if pressed alone to /.
    – Hotschke
    Apr 12, 2020 at 13:19

3 Answers 3

6

This is not possible. In the terminal, no key code is generated for modifiers alone.

Gvim also has no support for this, partly because there is no valid way to represent the key using the map commands.

1
  • Oh well, Looks like I will map ll to / then. Thanks.
    – iProgram
    Mar 6, 2015 at 11:37
3

Looking at the keycodes, towards the end of the table is:

<M-...>         alt-key or meta-key             meta alt <M-
<A-...>         same as <M-...>                 <A-
<D-...>         command-key (Macintosh only)    <D-

Combinations would look like <D-M-x>.

Though I don't think a combination of modifiers alone can be mapped (Ctrl-Shift,Cmd-Alt, etc.).

0
0

Map Cmd+Opt if pressed alone to / with Karabiner Elements

  1. Install Karabiner Elements

  2. Install following custom complex modification:

{
  "title": "Change Cmd_L and Option_L to Slash (/)",
  "rules": [
    {
      "description": "Change Command_L + Option_L (Alt) to slash (/) if pressed at the same time and without any other key.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_option",
            "modifiers": {
              "mandatory": [
                "left_command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to_if_alone": [
            {
              "key_code": "slash"
            }
          ],
          "to": [
            {
              "key_code": "left_option",
                "modifiers": [
                    "left_command"
                 ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_command",
            "modifiers": {
              "mandatory": [
                "left_option"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to_if_alone": [
            {
              "key_code": "slash"
            }
          ],
          "to": [
            {
              "key_code": "left_command",
              "modifiers": [
                    "left_option"
                 ]
            }
          ]
        }
      ]
    }
  ]
}

i) Copy json file to the correct location:

$ cp cmd-opt-alone-to-slash.json ~/.config/karabiner/assets/complex_modifications

ii) Import rules from Karabiner-Elements Preferences. Karabiner-Elements Preferences > Complex Modifications > Rules > Add rule

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.