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).
What This Guide Achieves
| Goal | Status |
|---|---|
| Install VS Code on Ubuntu-based OS | Done |
| Configure essential extensions for Linux development | Done |
| Set up Stata integration (run do-files from VS Code) | Done |
| Configure keybindings for productivity | Done |
| Understand VS Code file locations on Linux | Done |
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
.exeinstaller; you use.deborapt - 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
Method 1: Download .deb from Microsoft (Recommended)
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
.debversion is generally preferred.
Verify Installation
code --version
VS Code File Locations on Linux
| File | Linux Path | Windows 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
| Extension | ID | Purpose |
|---|---|---|
| GitLens | eamodio.gitlens | Git blame, history, and diff tools |
| Error Lens | usernamehw.errorlens | Show errors/warnings inline |
| Path Intellisense | christian-kohler.path-intellisense | Auto-complete file paths |
| Bracket Pair Colorizer | Built-in (enable in settings) | Visual bracket matching |
| Material Icon Theme | pkief.material-icon-theme | Better file icons in sidebar |
For Markdown and Documentation
| Extension | ID | Purpose |
|---|---|---|
| Markdown All in One | yzhang.markdown-all-in-one | Shortcuts, TOC generation, preview |
| markdownlint | davidanson.vscode-markdownlint | Markdown style linting |
For Stata Integration
| Extension | ID | Purpose |
|---|---|---|
| Stata Enhanced | kylebarron.stata-enhanced | Syntax highlighting for .do files |
| multi-command | ryuta46.multi-command | Chain 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:
| Script | Location | Purpose |
|---|---|---|
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:
- VS Code copies code to clipboard (internally, no shell interpretation)
- Script writes clipboard to a temp
.dofile (avoids bash interpreting Stata syntax) - Script sends
do "/tmp/stata_selection_run.do"to Stata via clipboard + paste - 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
| Action | Keybinding |
|---|---|
| Run entire do-file | Ctrl+Enter |
| Run selected lines/chunk | Select code → Shift+Enter |
| Run a single line | Ctrl+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 filenamefrom 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) needchmod +xto be executable - VS Code’s terminal inherits your user permissions
- You can run
chmod +x filename.shdirectly from VS Code’s terminal
What Didn’t Work (and Why)
| Approach Tried | Why It Failed |
|---|---|
Using stata.* keys in VS Code settings.json | These keys only work if a specific Stata extension reads them — most don’t |
Passing ${selectedText} as shell argument for Stata | Bash interprets backticks, comments, and special characters in Stata code |
| Pasting raw Stata code into Stata’s command bar | Command bar executes one line at a time, doesn’t support block comments |
| Using Wayland with wmctrl/xdotool automation | These tools only work on X11 — must use Xorg session |
| Installing VS Code from snap for Stata workflow | Snap sandboxing can interfere with clipboard and window management tools |
Related Guides
- Stata 19 Complete Guide — Full Stata installation and VS Code integration
- Stata 19 MP with Antigravity — Reuse the VS Code-style Stata workflow in Antigravity
- Stata Cross-Platform — Making do-files work on Windows + Linux + macOS
- Display Server Guide — Why X11 is needed for automation
Discussion