Skip to content

Instantly share code, notes, and snippets.

@adumont
Last active November 29, 2023 20:13
Show Gist options
  • Save adumont/a2ad60828bfacd78601e3e7f12fcafa3 to your computer and use it in GitHub Desktop.
Save adumont/a2ad60828bfacd78601e3e7f12fcafa3 to your computer and use it in GitHub Desktop.

Python - Surround with a function in VScode.md

You can create a code snippet for your function call by going to File > Preferences > User Snippets and selecting the language you're working with (in this case, Python). Then, select "New Global Snippets file" and enter a name for your snippet file.

{
	"myfunc": {
		"prefix": "Surround with...",
		"body": [
			"${1:function}(${TM_SELECTED_TEXT})"
		],
		"description": "Wrap selected text with function()"
	}
}

Ctrl-Shift-P, select Open Keyboard Shortcuts (JSON) and add:

[
    {
        "key": "ctrl+shift+8",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus  && !editorReadonly",
        "args": {
            "langId": "python",
            "name": "myfunc",
        },
    }
]

Now you can select some text and press Ctrl+Shift+8, and simply enter the name of the function!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment