MS Python 插件.
这是微软官方的 Python 插件,已经自带很多功能.下面是插件功能描述,其中部分内容我做了翻译.
a) Linting ( Prospector , Pylint , pycodestyle , Flake8 , pylama , pydocstyle , mypy with config files and plugins) 静态代码扫描(可以理解为代码语法和格式错误提示,支持多种 linter)
b) Intellisense (autocompletion with support for PEP 484 and PEP 526) 智能提示(自动补全,自动完成,包括了所在上下文的方法和变量)
c) Auto indenting 自动缩进
d) Code formatting ( autopep8 , yapf , with config files) 代码自动格式化
e) Code refactoring (Rename, Extract Variable, Extract Method, Sort Imports) 代码重构(重命名,提取变量,提取方法,对 import 排序)
f) Viewing references, code navigation, view signature 查看引用,代码导航,查看签名
g) Excellent debugging support (remote debugging over SSH, mutliple threads, django, flask) 完美的调试支持(通过 SSH 远程调试,多线程,django,flask)
h) Running and debugging Unit tests ( unittest , pytest , nose , with config files) 运行和调试单元测试
i) Execute file or code in a python terminal 在 python 终端执行文件或代码
j) Snippets 代码片段
可见已经很强大了,满足了基本的需要.比如要自动格式化代码,只需要按下 Alt+Shift+F,vscode 就会调用 autopep8 自动格式化代码(题外话,VisualStudio 是 Ctrl+K,D).
但是我们不满足于此,我们要实现自己的 style.例如 Snippets,比如我们输入 for,在提示框中选择对应的 snippet:
点击回车或者 tab,就变成了:
我们如果要定义自己的 Snippets,比如我们想要快速输入 for xx in enumerator() 方式遍历,该如何做呢.首先打开文件—首选项—用户代码片段.vscode 会提示你选择语言,我们输入 Python 并回车,打开了 python.json.内容格式为 json,在根级下面新增一个自己的 object,内容如下:
for target_list in expression_list:
pass
这样在我们输入 for/enum 再按回车后,就自动生成了:
"For in enumerator": {
"prefix": "for/enum",
"body": [
"for ${1:index}, ${2:item} in enumerate(${3:array}):",
" ${4:pass}"
],
"description": "For statement with enumerator"
}
光标停留在 index 上并选中该词,我们可以直接修改完,按 tab 切换到 item,然后是 array,pass.
for index,
item in enumerate(array) : pass
Guides:缩进提示
有人说,vscode 里已经有缩进参考线了呀,还需要 Guides 做什么?的确,vscode 有缩进线,但是这个 Guides 比自带的缩进线更好,请看下图:
当前所在的级别缩进线会变红,当前在哪一级一目了然.
vscode-icons 文件图标集,支持更多文件类型,最重要的,颜值更高!
关于调试时自动暂停在第一句.
这里可以配置,就是在 lauch.json 文件中,有个 "stopOnEntry":true,设置为 false 就可以不再暂停.
其他
还有一些 python 插件配置,就不一一细讲了,大家可以在设置中(文件 - 首选项 - 设置)搜索得到.包括:
a) autopep8/yapf:自动格式化代码;
b) pylint-django:兼容 django 的 pylint,需要用 pip install;
c) flakes8:错误提示.
希望大家玩的愉快~
来源: https://www.cnblogs.com/pleiades/p/8284562.html