0

I've recently switched from PyCharm to VSCode for my Python programming and am using Microsoft's own Python extension for VSCode. While most of the extension's auto-completes work great for me, some of the results are unwanted.

For example, if I go into a class and write def, I get a few possibilities in the autocomplete popup. I select class method and the editor auto-completes to the following:

def funcname(self, parameter_list):
    pass

which is great, and also allows moving through funcname, parameter_list and pass with the TAB key.

However if I instead override a method, writing e.g. def __ini, I get the option to autocomplete to __init__ and selecting this option results in:

def __init__(self, *args, **kwargs):
 return super().__init__(*args, **kwargs)

Normally I don't want to return anything from __init__ (and indeed, even more generally, I usually don't want to return the results of the superclass's method). Additionally, this auto-complete template is indented with a single space instead of a tab, which now results in indentation errors if I don't manually fix it (which kind of defeats the purpose of autocompletion).

I would like this second autocomplete to function like the first one, with the exception of filling in the parameter list automatically.

My question is, where are these autocomplete templates defined and how can I edit them?

Mate de Vita
  • 1,102
  • 12
  • 32

1 Answers1

1

What I think you're looking for is user-defined snippets. The link below has a guide on how to make them and you edit them from the same preferences area, as well, including tabstops and scope for where snippet applies.

https://code.visualstudio.com/docs/editor/userdefinedsnippets

Sam
  • 91
  • 7
  • This seems to be what I'm looking for, but is there a way I can see the Python extension's own snippets? It would help me override their snippets with my own. – Mate de Vita Mar 07 '19 at 10:53
  • I think establishing your own "global" snippets should override the Py extension snippets. – Sam Mar 07 '19 at 17:34