Vim icon indicating copy to clipboard operation
Vim copied to clipboard

How to map Command key to Control key when using vscode

Open aruku7230 opened this issue 4 years ago • 7 comments

I already mapped "Caps Lock" key to "Command" key using System Preferences of macOS, as I use "Command" key frequently when using most application.

When using vscode with vim keymap, I use "Control" key at most time. Is it possible to map "Command" key (actually the "Caps Lock" key in keyboard) to "Control" when using vscode?

aruku7230 avatar Mar 21 '21 03:03 aruku7230

In Vim 8.2 :help <D- shows that mappings can be defined for the Command key. Not sure if that helps.

(By the way, one thing I loved about using VSCodeVim is that when I switch between macOS and Linux, the Vim keyboard shortcuts stay the same!)

joeytwiddle avatar Mar 24 '21 07:03 joeytwiddle

I have the same requirement, has anyone solved it?

liudianwei avatar Apr 29 '21 01:04 liudianwei

Things I tried which didn't work:

    "vim.normalModeKeyBindings": [
        {
            "before": ["<Cmd>"],
            "after": ["<Ctrl>"]
        }
    ]
    "vim.normalModeKeyBindings": [
        {
            "before": ["<D>"],
            "after": ["<C>"]
        }
    ]

lahwran avatar May 19 '21 18:05 lahwran

There is a Mac app called "Karabiner" (latest version "Karabiner Elements") which might be able to help you.

I know it can switch Cmd and Ctrl. But can it do it just for one specific app? Perhaps...

joeytwiddle avatar May 28 '21 10:05 joeytwiddle

Unfortunately Karabiner do not have a feature change the function of keys for specific app.

aruku7230 avatar May 28 '21 11:05 aruku7230

Unfortunately Karabiner do not have a feature change the function of keys for specific app.

Karabiner does allow you to set conditions, including limiting the rule to specific apps. It will affect absolutely everything (including ⌘-tab, etc), so you might want to refine this a bit, but the following complex modification works for me:

{
  "description": "Map command to control in VS Code",
    "manipulators": [
    {
      "conditions": [
      {
        "bundle_identifiers": [
          "^com.microsoft.VSCode"
        ],
        "type": "frontmost_application_if"
      }
      ],
      "from": {
        "key_code": "left_command"
      },
      "to": [
      {
        "key_code": "left_control"
      }
      ],
      "type": "basic"
    }
    ]
}

aikinai avatar Apr 18 '22 16:04 aikinai

Is there any simple solution to this problem in 2024?

jensenojs avatar Jun 24 '24 06:06 jensenojs