VS Code Python extension Auto-complete Templates

醉酒当歌 提交于 2021-01-29 08:17:22

问题


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?


回答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



来源:https://stackoverflow.com/questions/55025757/vs-code-python-extension-auto-complete-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!