How can I add a colon automatically at the end of "def", "for" and "if" statements in Python for Visual Studio Code just like in Spyder?
You can use code snippets to insert code with the colon included. Otherwise you will need to create an extension which implements formatting-on-type to do this for you.
Shift
+ Enter
— Insert colon at the end of line and continue on the same line
Ctrl
/ CMD
+ Enter
— Insert colon at the end of line and continue on the new line
Ctrl
/ CMD
+ Alt
+ Enter
— Insert colon and stay at the same position
By default shortcut will work only with Python files. If you want to mimic this behaviour in other languages as well, but without a colon:
keybindings.json
( Ctrl
/ CMD
+ Shift
+ P
, type >Open Keyboard Shortcuts (JSON)
) {
"key": "cmd+enter",
"command": "editor.action.insertLineAfter",
"when": "editorTextFocus && !editorReadonly && editorLangId != 'python'"
}
转到扩展并搜索 pylint,然后安装 pylint 扩展
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.