VS Code Python扩展自动完成模板 [英] VS Code Python extension Auto-complete Templates

查看:72
本文介绍了VS Code Python扩展自动完成模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从PyCharm切换到VSCode进行Python编程,并且正在使用Microsoft自己的VSCode Python扩展.虽然大多数扩展程序的自动完成功能对我来说都很有用,但其中一些结果是不需要的.

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.

例如,如果我上一堂课并写 def ,则在自动完成弹出窗口中会出现一些可能性.我选择类方法,编辑器将自动完成以下操作:

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

很棒,还可以使用TAB键在 funcname parameter_list pass 之间移动.

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

但是如果我改写一个方法,写例如 def __ini ,我可以选择自动完成 __ init __ 并选择此选项将导致:

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)

通常,我不想从 __ init __ 返回任何内容(实际上,甚至更一般地说,我通常也不想返回超类的方法的结果).此外,此自动完成模板的缩进使用单个空格而不是制表符,如果我不手动修复它,现在会导致缩进错误(这会破坏自动完成的目的).

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

这篇关于VS Code Python扩展自动完成模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆