Search code examples
visual-studio-codevscode-snippets

vscode auto parentheses not working some cases, can i write some words by a keyboard shortcut?


It's hard for me to press the shift+9 and then shift+0 when I need parentheses.

I want when I type print and press tab or enter then be converted to print() or when I am defining or calling a function. But this doesn't happen. I tried with python extension, pylance and tabnine (free version). Maybe you would suggest a user snippet but they are not very pleasant in this way. I mean if I create a snippet with pa key and () body, I must first write print pa to be converted to print () and then I must remove space in middle.

It would be great if there was a way to write a few words just by a shortcut. For example, control+enter become to ()

P.S. English is not my first language, sorry if there are grammatical mistakes.


Solution

  • {
      "key": "ctrl+enter",               // whatever keybinding you like
      "command": "editor.action.insertSnippet",
      "when": "editorTextFocus",
      "args": {
        "snippet": "()"
      }
    },
    

    That is a keybinding fro your keybindings.json file.

    This does the same:

    {
      "key": "ctrl+enter",
      "command": "type",
      "when": "editorTextFocus",
      "args": {
        "text": "()"
     }
    },
    

    also a keybinding for the keybindings.json file.