Blog Post

Key mappings in Visual Studio Code

,

At a recent conference I was asked how I executed code during my presentation.

Running code during a presentation should be as smooth as possible…so in VS Code I have a couple of custom key mappings set up and I thought I’d write a quick blog detailing what they are and what they do.

This is the first set: –

    {
        "key": "ctrl+/",
        "command": "workbench.action.terminal.focus",
        "when": "!terminalFocus"
    },
    {
        "key": "ctrl+/",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    }

What this does is allow me to switch from an editor window to the terminal and back again using Ctrl+/

Like this…

The next key mapping I have is…

    {
        "key": "ctrl+;",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                "workbench.action.terminal.runSelectedText",
                "workbench.action.focusActiveEditorGroup"
            ]
        }
    }

This requires an extension called multi-command and what it allows me to do is select code in an editor and execute it in the terminal by pressing Ctrl+;

It also allows for multiple lines of code to be highlighed but if nothing is highlighted, it’ll just run whatever is on the existing line. Once the code is executed, it’ll return the cursor to the editor (instead of remaining in the terminal).

Like this…

These key mappings allow me to run through code in presentations nice and smoothly…so the session can focus on the code itself and not me stumbling around trying to run it!

You can set up these key mappings in your install of VS Code by opening the command palette and searching for “Preferences: Open Keyboard Shortcuts (JSON)”. This’ll open a keybindings.json file in the editor.

I’ve dropped my full file into a Gist here.

Thanks for reading!

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating