VS-Code on Linux

A quick setup guide


Posted: November 9, 2022

This is a guide to how I set up Microsoft Visual Studio Code on Linux, please note that this is not a tutorial and your preferences may vary. It is intended as a quick start guide for novice users and contains frequently used settings from colleagues and myself.

Installation

Follow the official guide from Visual Studio Code on Linux and install VS-Code onto your Linux distribution. Or setup a containerized version of VS-Code such as the Snap or Flatpak version.

I will be using the Flatpak version of VS-Code in this instance, as I am experimenting with using Fedora Silverblue.

Settings

Now that VS-Code is installed, open up the settings page using the gear icon in the lower left, or by pressing Ctrl+Comma.

Then open the settings.json file from the settings page with the Open Settings (JSON) button in the top right. This settings file can also be found at config/Code/User/settings.json.

These are my current settings, but again, feel free to tweak these to your liking:

{
    "terminal.integrated.persistentSessionReviveProcess": "never",
    "terminal.integrated.enablePersistentSessions": false,

    "git.autofetch": true,
    "git.confirmSync": false,

    "editor.renderWhitespace": "all",
    "editor.rulers": [ 80 ],

    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "files.insertFinalNewline": true,

    "window.menuBarVisibility": "toggle",
    "workbench.startupEditor": "none",
    "telemetry.telemetryLevel": "off",

    "terminal.integrated.defaultProfile.linux": "toolbox",
    "terminal.integrated.profiles.linux": {
        "bash": {
            "path": "/usr/bin/flatpak-spawn",
            "args": ["--host", "--env=TERM=xterm-256color", "bash"]
        },
        "toolbox": {
            "path": "/usr/bin/flatpak-spawn",
            "args": ["--host", "--env=TERM=xterm-256color", "toolbox", "enter"]
        }
    }
}

Now is a good time to create a backup of the settings.json file, so you can always revert to these settings and use them again with future installations of VS-Code.

Settings explained

The first two options will make the integrated terminal within VS-Code non-persistent. Which means each instance of VS-Code will start with no command history, as this can mess up toolbox containers.

"terminal.integrated.persistentSessionReviveProcess": "never",
"terminal.integrated.enablePersistentSessions": false,

The next two should explain themselves, these should really be set by default…

"git.autofetch": true,
"git.confirmSync": false,

These settings adjust the editor view and file saving behavior, one being a handy ruler to indicate the 80 character limit, and the files ones make sure we do not save and commit unnecessary whitespace characters.

"editor.renderWhitespace": "all",
"editor.rulers": [ 80 ],

"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,

Next are some ones you may want to leave out, these do not effect editing files.

"window.menuBarVisibility": "toggle",
"workbench.startupEditor": "none",
"telemetry.telemetryLevel": "off",

If using the Flatpak version of VS-Code, you might want to use your host’s shell and/or toolbox sessions from the integrated terminal. For this to work, we need to add the following lines:

"terminal.integrated.defaultProfile.linux": "toolbox",
"terminal.integrated.profiles.linux": {
    "bash": {
        "path": "/usr/bin/flatpak-spawn",
        "args": ["--host", "--env=TERM=xterm-256color", "bash"]
    },
    "toolbox": {
        "path": "/usr/bin/flatpak-spawn",
        "args": ["--host", "--env=TERM=xterm-256color", "toolbox", "enter"]
    }
}

Extensions

Undoubtedly, extensions change the most from use case to use case. Therefore, the following list of extensions may not be relevant, and I’ll leave it up to you to decide what to install or not:

  1. Code Spell Checker, avoid typos whilst writing code and documentation.
  2. Pylint, popular code linter for Python files.
  3. ShellCheck, Integrates the shellcheck linter for shell scripts.

Make sure to also checkout the wide range of extensions available in the Microsoft Extensions Marketplace for VS-Code, there is a good chance that the right linter or spell checker is available for you!