How to install Visual Studio Code

Visual Studio Code (VSCode) is easy to install and configure. You just need to remember a few keyboard shortcuts.

  • Download the latest .deb file of VSCode from here.

  • VSCode is being developed rapidly and new releases appear frequently. If you have an older version of VSCode, uninstall it first:

$ sudo apt remove code
  • Install the downloaded VSCode:
$ sudo dpkg -i vscode-you-downloaded.deb
  • Start in a root directory of your code:
$ code .
  • VSCode will start up using all the files and directories inside the current directory as belonging to a project. While it is indexing the files, you will see a red flame icon in bottom-right corner. Once the flame goes away, you are ready to edit files!

  • Extensions: VSCode is no fun without extensions for your favorite languages (say C++ or Python) or your favorite features (say Vim). To install extensions use keyboard shortcut Ctrl+P and type ext install. You can search and install extensions from the VSCode Marketplace. Many extensions might restart VSCode to get enabled.

  • Settings: VSCode can handle both user settings (works across all projects) and workspace settings (works only for a particular project). All settings are set in JSON files. You can choose File → Preferences to open these. To set something, you need to copy that line from default settings to settings.json.

Tried with: Visual Studio Code 1.4 and Ubuntu 16.04

Visual Studio Code extensions that I use

  • CPP Tools: The official extension for working with C++ code. Automatically indexes all code in the currently open directory, offers auto-completion and syntax highlighting.

  • Python by Don Jayamanne: There are many Python extensions, but this seems to be the most popular one. Syntax highlighting, indexing and code completion.

  • Vim: There are many Vim extensions, but this seems to be the most popular one. It has entire universes to traverse before it can be as good as Vrapper, the Vim extension for Eclipse. This VSCode extension offers very basic navigation and editing commands.

  • Git Blame: This extension does one little thing that I need everyday to work with code from other people: know who modified a line of code. This extension shows that for the current line in the status bar.

  • Matlab: I need to regularly browse through some MATLAB files. This extension offers syntax highlighting of Matlab files.

Tried with: Visual Studio Code 1.4 and Ubuntu 16.04

Visual Studio Code Keyboard Shortcuts

I am finding Visual Studio Code to be very useful as a light IDE and editor for C++ and Python code on Linux.

Some keyboard shortcuts that I find useful:

Ctrl + B:         Toggle sidebar
Ctrl + P:         Search for file to open
Ctrl + Shift + F: Search for text in files
Ctrl + Shift + P: Editor commands
Ctrl + G:         Jump to line number
Ctrl + Tab:       Switch between open editors
Ctrl + Shift + O: Jump to symbol in current file
Ctrl + T:         Jump to symbol in current workspace
Ctrl + `:         Open terminal
F12:              Go to definition
Ctrl + Alt + -:   Go back
Ctrl + /:         Toggle line comment

Some user interface tips:

  • Single click on filenames in the Side Bar opens files into the same editor tab, replacing the earlier one. This is useful when browsing through files. Notice that the filename is in italics on the editor tab in this mode.

  • Double click on filenames in the Side Bar opens file in a new editor tab. The file owns that editor tab. Notice that the filename is not in italics on the editor tab.

  • Ctrl + single click on filename in Side Bar to open it in existing editor tab in second vertical split.

  • Ctrl + double click on filename in Side Bar to open it in new editor tab in second vertical split. This file will own the tab.

  • What if you opened a file using single click, but now wish it owned the tab, so that it will not be replaced when you open next file? Aha, Visual Studio Code has you covered! Double click the filename on the tab. You will see that the italics is removed. The file now owns this tab.