VS Code Setup on Linux

Install VS Code via the official .deb repository, configure essential extensions, and fix common Linux-specific issues (font rendering, terminal path).

Beginner Verified Working Updated 6 min read Tested on Zorin OS 18.1 Pro (Ubuntu 24.04 Noble base) Hardware Lenovo ThinkPad L14 Gen 2

What This Guide Achieves

GoalStatus
Install VS Code on Ubuntu-based OSDone
Configure essential extensions for Linux developmentDone
Set up Stata integration (run do-files from VS Code)Done
Configure keybindings for productivityDone
Understand VS Code file locations on LinuxDone

The Problem (Windows User Perspective)

VS Code on Linux works almost identically to Windows — same UI, same extensions, same settings. The main differences are:

  • Installation method — no .exe installer; you use .deb or apt
  • Settings location~/.config/Code/User/ instead of %AppData%\Code\User\
  • Terminal integration — VS Code’s built-in terminal gives you a real bash shell
  • Some extensions need Linux tools — automation tools like wmctrl, xdotool, xclip (X11 only)

Installation

wget -O vscode.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64"
sudo apt install ./vscode.deb
rm vscode.deb

This automatically adds Microsoft’s apt repository, so future updates come through sudo apt upgrade.

Method 2: Using Snap

sudo snap install code --classic

Note: The snap version may have minor differences with file system access due to sandboxing. The .deb version is generally preferred.

Verify Installation

code --version

VS Code File Locations on Linux

FileLinux PathWindows Equivalent
User settings~/.config/Code/User/settings.json%AppData%\Code\User\settings.json
Keybindings~/.config/Code/User/keybindings.json%AppData%\Code\User\keybindings.json
Extensions~/.vscode/extensions/%USERPROFILE%\.vscode\extensions\
Workspace settings.vscode/settings.json (in project folder)Same
Tasks.vscode/tasks.json (in project folder)Same

Essential Extensions

For General Development

ExtensionIDPurpose
GitLenseamodio.gitlensGit blame, history, and diff tools
Error Lensusernamehw.errorlensShow errors/warnings inline
Path Intellisensechristian-kohler.path-intellisenseAuto-complete file paths
Bracket Pair ColorizerBuilt-in (enable in settings)Visual bracket matching
Material Icon Themepkief.material-icon-themeBetter file icons in sidebar

For Markdown and Documentation

ExtensionIDPurpose
Markdown All in Oneyzhang.markdown-all-in-oneShortcuts, TOC generation, preview
markdownlintdavidanson.vscode-markdownlintMarkdown style linting

For Stata Integration

ExtensionIDPurpose
Stata Enhancedkylebarron.stata-enhancedSyntax highlighting for .do files
multi-commandryuta46.multi-commandChain multiple commands on one keybinding

Install extensions from the command line:

code --install-extension kylebarron.stata-enhanced
code --install-extension ryuta46.multi-command

Stata Integration: Run Do-Files from VS Code

This is the most complex VS Code setup covered in these guides. The full details are in the Stata 19 Complete Guide, but here’s the summary.

Prerequisites

sudo apt install wmctrl xdotool xclip -y

These tools only work on X11 (Xorg), not Wayland. See the Display Server Guide for switching.

How It Works

Two custom shell scripts handle the VS Code → Stata communication:

ScriptLocationPurpose
stata_run_do.sh~/.local/bin/Runs an entire .do file in Stata GUI
stata_run_selection.sh~/.local/bin/Runs selected code in Stata GUI

The workflow:

  1. VS Code copies code to clipboard (internally, no shell interpretation)
  2. Script writes clipboard to a temp .do file (avoids bash interpreting Stata syntax)
  3. Script sends do "/tmp/stata_selection_run.do" to Stata via clipboard + paste
  4. Stata executes the temp file as a proper do-file

Keybindings

Add to ~/.config/Code/User/keybindings.json:

[
  {
    "key": "ctrl+enter",
    "command": "workbench.action.tasks.runTask",
    "args": "Run do-file in Stata GUI"
  },
  {
    "key": "shift+enter",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "editor.action.clipboardCopyAction",
        {
          "command": "workbench.action.tasks.runTask",
          "args": "Run selection in Stata GUI"
        }
      ]
    },
    "when": "editorTextFocus"
  }
]

Usage

ActionKeybinding
Run entire do-fileCtrl+Enter
Run selected lines/chunkSelect code → Shift+Enter
Run a single lineCtrl+L (select line) → Shift+Enter

For the complete setup including script contents and tasks.json, see the Stata 19 Complete Guide Parts 5-7.


Useful Settings for Linux

Add to ~/.config/Code/User/settings.json:

{
  // Use bash as default terminal
  "terminal.integrated.defaultProfile.linux": "bash",

  // Font with good Unicode support (check what's installed on your system)
  "editor.fontFamily": "'Fira Code', 'Droid Sans Mono', 'monospace'",

  // File associations
  "files.associations": {
    "*.do": "stata",
    "*.ado": "stata",
    "*.mata": "stata"
  },

  // Auto-save (optional — some prefer manual save)
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1000,

  // Trim trailing whitespace on save
  "files.trimTrailingWhitespace": true,

  // Show hidden files in file explorer
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true
  }
}

Linux-Specific Tips

Opening VS Code from Terminal

# Open current directory
code .

# Open a specific file
code /path/to/file.py

# Open a specific folder
code /path/to/project

# Open VS Code with a new empty window
code -n

Using the Integrated Terminal

  • Ctrl+` — Toggle the terminal panel
  • Ctrl+Shift+` — Open a new terminal
  • The terminal is a real bash shell — you can run any command directly
  • code filename from the integrated terminal opens the file in a new tab

VS Code and File Permissions

Unlike Windows, Linux files have execute permissions. VS Code respects these:

  • Scripts (.sh) need chmod +x to be executable
  • VS Code’s terminal inherits your user permissions
  • You can run chmod +x filename.sh directly from VS Code’s terminal

What Didn’t Work (and Why)

Approach TriedWhy It Failed
Using stata.* keys in VS Code settings.jsonThese keys only work if a specific Stata extension reads them — most don’t
Passing ${selectedText} as shell argument for StataBash interprets backticks, comments, and special characters in Stata code
Pasting raw Stata code into Stata’s command barCommand bar executes one line at a time, doesn’t support block comments
Using Wayland with wmctrl/xdotool automationThese tools only work on X11 — must use Xorg session
Installing VS Code from snap for Stata workflowSnap sandboxing can interfere with clipboard and window management tools

Discussion