简体   繁体   中英

VS Code Python extension Auto-complete Templates

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 eg 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM