Visual Studio Code#

This page will help you configure Visual Studio Code (VSCode) to be consistent with coding standards and development practices.

Installation#

Ubuntu-based Linux distros#

Install repository and key of the VS Code package to enable auto-updating using the system’s package manager.

sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

Then update the package cache and install the package using:

sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install code # or code-insiders

After VS Code is successfully installed make it a default editor for git.

git config --global core.editor "code --wait"

For alternative ways of installing VS Code you can consult official Microsoft page.

Extensions#

As with most advanced editors, a lot of VSCode’s functionality comes from extensions, which can be installed directly from the editor GUI.

The official (Microsoft-maintained) extensions generally have quite good documentation, and this guide does not attempt to duplicate anything that can be found there.

Note

Adding an extension to VSCode does not always automatically enable it when editing files remotely. When you first open a remote editing window on a particular server, you should check your extensions to ensure the ones you need are installed and enabled there.

Useful extensions#

C/C++:

The official C++ extension, from Microsoft.

Python:

The official Python extension, from Microsoft.

Python Indent:

As of this writing, VSCode’s automatic indentation for Python isn’t very good. This extension makes it a lot better - still not as good as (at least) Emacs or Sublime, but good enough that the difference is rarely noticeable.

restructuredText:

Useful for writing Sphinx docs.

Remote Development, Remote - SSH:

Provides support for editing, browsing, and debugging code on a remote server from a local editor, over SSH.

Trailing Spaces:

Highlights and/or deletes trailing spaces, which Flake8 will otherwise complain about.

General extension recommendations#

Clipboard Ring:

Remembers the last few things you’ve copy/pasted; a very limited version of what (at least) Emacs does.

Git Graph:

An in-editor, easy-to-read version of git log --graph.

Git Lens:

In-editor git blame annotation and more.

Settings#

Here is a suggested settings file that will configure VSCode to match approved coding styles and ignore common temporary files our builds produce. This includes settings for some of the extensions recommended above. The "rulers" setting doesn’t affect actual indentation (unless you use the Rewrap extension or similar), but provides guides to help your own line length formatting.

Source code: settings.json

{
    "[cpp]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "[restructuredtext]": {
        "editor.wordWrap": "wordWrapColumn"
    },
    "editor.bracketPairColorization.enabled": true,
    "editor.detectIndentation": false,
    "editor.formatOnPaste": false,
    "editor.formatOnSave": false,
    "editor.formatOnSaveMode": "modifications",
    "editor.insertSpaces": true,
    "editor.renderWhitespace": "all",
    "editor.rulers": [
        80,
        100,
        120
    ],
    "editor.wordWrap": "on",
    "explorer.compactFolders": false,
    "files.associations": {
        ".clang-tidy": "yaml",
        ".codespellrc": "ini",
        "*.cpp.in": "cpp",
        "*.ipp": "cpp",
        "*.py.in": "python",
        "*.pyi.in": "python"
    },
    "files.exclude": {
        "**/__pycache__": true,
        "**/.coverage.*": true,
        ".git/**": true,
        "**/.pytest_cache": true,
        "build*/**": true,
        "cmake/build/": false,
        "**/*.vc.db*": true
    },
    "files.insertFinalNewline": true,
    "files.trimTrailingWhitespace": true,
    "files.watcherExclude": {
        "**/__pycache__": true,
        "build*/**": true,
        "cmake/build/": false,
        "**/*.vc.db*": true
    },
    "gitlens.codeLens.recentChange.enabled": false,
    "gitlens.codeLens.authors.enabled": false,
    "trailing-spaces.trimOnSave": true,
    "search.useGlobalIgnoreFiles": true,
}