简体   繁体   中英

Python Autocompletion in VS Code

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.

Switching from PyCharm to VSCode, I have finally found PyColonize

展柜

It adds these shortcuts:

  • 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:

  1. Open keybindings.json ( Ctrl / CMD + Shift + P , type >Open Keyboard Shortcuts (JSON) )
  2. Insert the following:
      {
        "key": "cmd+enter",
        "command": "editor.action.insertLineAfter",
        "when": "editorTextFocus && !editorReadonly && editorLangId != 'python'"
      }

For semicolons, see colonize

If you're switching to VSCode from PyCharm, take a look at pycharm-to-vscode-transition repository I've created to help smoothen such transition

转到扩展并搜索 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.

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