microsoft/vscode

OS Specific Keybindings

erichiller opened this issue ยท 10 comments

I have a company issued OSX machine, linux boxes and windows machines all of which I do dev work on, moving back and forth, I try to keep my settings in sync, it would be very nice to have an operating specific syntax for the keybindings file, much how tasks.json does.

{
    "version": "0.1.0",
    "windows": [
        {
            "key": "win+b",
            "command": "workbench.action.tasks.build"
        },{
            "key": "win+d",
            "command": "workbench.action.tasks.terminate"
        }
    ],
    "osx": [
        {
            "key": "cmd+b",
            "command": "workbench.action.tasks.build"
        },{
            "key": "cmd+d",
            "command": "workbench.action.tasks.terminate"
        }
    ]
}

Or better yet in line with #871 ...

{
    "windows": [
        {
            "key": "win+b",
            "command": [
                "workbench.action.tasks.terminate",
                "workbench.action.tasks.build"
            ]
        },{
            "key": "win+l",
            "command": "workbench.action.tasks.showLog"
        }
    ],
    "osx": [
        {
            "key": "cmd+b",
            "command": [
                "workbench.action.tasks.terminate",
                "workbench.action.tasks.build"
            ]
        },{
            "key": "cmd+l",
            "command": "workbench.action.tasks.showLog"
        }
    ]
}

For that matter it would be wonderful to have this ability for all of the user configurable settings

tasks.json is sitting in the workspace (presumably also checked in a git repo...), thus its need to support different values across different Operating Systems.

keybindings.json or settings.json are local to the user, since that's where more personal things should stay (i.e. not shared with the team).

I would personally not complicate the structure for the majority of users that don't need to jump across Operating Systems, I would go for something like keybindings.osx.json, keybindings.linux.json, settings.win.json, etc, which would overimpose the variants without the OS in their filename.

@bpasero @aeschli @jrieken - You are also heavy cross OS users and share the ownership of the config service. Thoughts?

I'm hitting the same issue where I would like to sync my settings cross machines, including Windows and OSX machines. The only thing that currently is not working well for me is keybindings.
It would be great to provide an option in user-specific keybinds to set "this is only valid for Windows".

Instead of scoping all of the keybindings, I agree that it makes more sense to allow creation of user-specific keybindings per platform in different files (so besides normal keybindings.json) have something like keybindings.osx.json.

Just as a thought, another option is introducing a platform property in the keybind itself or ability to have when property handle platform, e.g osWinOnly or !osOSX` or something in this style. But I personally like the idea of platform files.

I've been syncing my settings between Linux and OS X and am trying to resolve an issue where I'm loading custom CSS but the path picked up in the settings file by ~/ or $HOME don't seem to point to the same thing on the OS (might have to do with how I'm launching it in Linux). This might be something I can figure out, but in general I could see it being really nice to have any settings setup to be OS-specific, not just key bindings.

We've run into a similar issue with Python .venv support, where the pythonPath differs by OS but is otherwise seems sensible to store in the repo with other things that should be shared.

{
    // win
    "python.pythonPath": "${workspaceRoot}\\.venv\\Scripts\\python.exe",
    "python.formatting.provider": "yapf"
}

{
    // mac
    "python.pythonPath": "${workspaceRoot}/.venv/bin/python",
    "python.formatting.provider": "yapf"
}

Thanks for considering!

Here's my keybindings.json file, my dotfiles script symlinks that to the correct directory on each platform https://github.com/Tyriar/dotfiles/blob/master/modules/vscode/config/keybindings.json

Some of the keybindings don't make sense on mac in particular, for example this one which makes ctrl+k a chord on macOS:

{ "key": "ctrl+k ctrl+s",   "command": "workbench.action.openGlobalKeybindingsFile" },

Something like this would be sufficient for me without complicating the structure:

{ "key": "ctrl+k ctrl+s",   "command": "workbench.action.openGlobalKeybindingsFile",
  "when": "!isMac" },

I'd like for this feature to exist as well, mostly to integrate better with windows. I use vscode across Mac, Linux and Windows and my issue is with the git.path setting.

Leaving settings.json as platform agnostic and making os-specific files that can be shared on all OSs for convenience, but only applied on their target platform seems like a good idea.

Good implementation. Thanks!

verified via code review