Search code examples
rvisual-studio-codequarto

Add Keyboard Shortcuts for R Chunks in Quarto Docs Using VSCode


Is it possible to add keyboard shortcuts for R chunks in quarto documents using vscode?

I'm trying to use shortcuts like the pipe operator %>% (ctrl+shift+m) and others. I thought I should do this by including something like the code below in the keybinds.json file, but it doesn't work for me:

    {
      "key": "ctrl+shift+m",
      "command": "type",
      "when": "editorLangId == 'r' || editorTextFocus && editorLangId == 'qmd'",
      "args": { "text": " %>% " }
    },

Solution

  • I assume keybinds.json is a typo in your post (the correct filename is keybindings.json).

    Provided I have understood you correctly, here is my keybindings.json

    // Place your key bindings in this file to override the defaults
    [{
        "key": "ctrl+shift+m",
        "command": "type",
        "args": { "text": "%>%" },
        "when": "editorTextFocus"
      }
    ]
    

    Ctrl+Shift+m then places "%>%" at the current position of the cursor.