DEV Community

dev0928
dev0928

Posted on

VS Code Extensions / Shortcuts for Python / Web

I use Visual Studio Code editor by Microsoft for Python development. I find below shortcuts and extensions particularly very useful during application development. Hope you find them useful as well!

Python extension for Visual Studio Code by Microsoft

With over 20 million installs, this is one of the most popular extensions for Python development in VS Code. Some of the commonly used editor options are:

  • Go to Definition (F12) jumps from the current code into the code that defines an object. This command is especially useful when working with libraries and want to learn more about them.
  • Peek Definition (Alt+F12), is similar, but displays the definition directly in the editor.
  • To run a specific section of code in Python, highlight the section and press shift + Enter. This runs just the highlighted portion of code from the Python file.
  • To enable brackets completion and linting - Press ctrl + shift + p and type settings.json to get the settings file. In settings.json file, add below:
{
    "python.linting.enabled": true,
    "python.autoComplete.addBrackets": true,
}
Enter fullscreen mode Exit fullscreen mode
  • To get a printable reference of all shortcuts in VS Code: Press ctrl + shift + p and type Keyboard Shortcuts Reference in the search box. This will take you to the shortcuts link containing nice printable version of shortcuts in a pdf format.
  • Please note default keyboard shortcuts could be changed using Code > Preferences option.

Visual Studio IntelliCode by Microsoft

This is again another popular extension that helps with code completion. Pausing or pressing ctrl + space after module name activates and displays list of code completion options.

Better Jinja by Samuel Colvin

Jinja code added in the html template usually looks unformatted. To add colorization effect, install Better Jinja by Samuel Colvin. Then add below association in settings.json file

{
    "files.associations": {
       "*.html": "jinja-html"
    }
}
Enter fullscreen mode Exit fullscreen mode

Flask snippets by cstrap

Flask snippets by cstrap provides shortcuts for generating commonly used snippets in Flask and Jinja. Once extension is installed, typing hw in the editor generates below snippet:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()
Enter fullscreen mode Exit fullscreen mode

Python DocString Generator by Nils Werner

This Python DocString Generator extension provides a consistent way to provide documentation to Python functions and modules.

References

https://code.visualstudio.com/docs/python/editing

Top comments (0)