Synopsis:
Visual Studio Code, a.k.a. VS Code, is a lightweight text editor with plugins that provide
an Integrated Development Environment well suited to individual and small team coding in Rust, C++, C#, and Python.
This help provides instructions for installation, setup, and some example usage.
Visual Studio Code works in Windows, Linux, and macOS. Builds and executions can work From
an integrated terminal window (PowerShell, Cmd, Bash, macOS Terminal) using these cmdline project managers:
Rust | Cargo |
C++ | CMake, MsBuild |
C# | dotnet |
Python | python interpreter |
VS Code supports plugins for all these languages that provide debug launch scripts, intellisense, and error
flags. It also provides a contained terminal window we will use to initiate builds from the command line
and executions of successful build products.
1. Visual Studio Code Editor:
Figure 1. VS Code IDE
Installation:
Download Visual Studio Code, a.k.a. VS Code. This
works for Windows, Linux, and macOS. Then run installer from Downloads folder.
IDE Setup:
There are three things you may wish to change in the default configuration:
-
The terminal panel, Figure 1 on the right, is placed by default at the bottom of the IDE window.
It works better for me to have it on the right. You can place it wherever you like with
settings (click Gear icon at left bottom -> settings):
Settings -> User -> search for "Panel Default Location"
-
By default the IDE shows a code Minimap on the right of the code editing panel. You can disable
that with:
Settings -> User -> TextEditor -> Minimap
-
You may wish to change the default terminal used by VS Code:
Settings -> Search for Terminal
Terminal -> Integrated -> Default profile
right click to see list: Command Prompt, PowerShell, Git Bash, ...
You will find it convenient to use the keyboard shortcuts:
-
"ctrl /" to toggle comments
on selected lines
-
"ctrl [ and ctrl ]" to control indenting of selected lines
-
Also, to open integrated terminal in any folder, click top menu File, select "Open Folder" and right click any file in the folder.
Then select "Open in Integrated Terminal". This is particularly useful when
you open a workspace folder (any folder with .vscode subfolder).
Other Settings:
To change other settings:
-
"settings -> Editor -> uncheck Accept Suggestion on Commit Character" to avoid many
spurious insertions of unwanted suggestions.
-
"settings -> search for menu -> select Menu Bar Visibility" to show/hide top menu
-
"F11" to toggle full screen mode
-
"View -> Command Palette -> .Net: Generate Assets for Build and Debug" enables Run
-> Start Debugging of .Net programs.
Have to have editor open in project directory.
-
"ctrl K, ctrl T -> select editor theme" to select one of many alternatives
-
"settings -> workbench -> appearance -> color customizations" to set terminal colors
-
"File -> Preferences -> Settings" to change lots of defaults
-
"File -> Preferences -> Settings -> user -> Features -> Terminal" to change Terminal defaults
-
"View -> Command Pallet -> Preferences: Open Settings (JSON)" to edit any user setting manually
Settings Details
Figure 4. VS Code Project launch Settings
Figure 5. VS Code User Settings
The settings you will manage most often are local settings for each project, found in a .vscode folder
at the top level of your project. Initially that folder doesn't exist, and you don't need
to explicitly create it. VS Code creates it for you the first time you click on the Run or Terminal -> Run Task
menus. You will be asked if you want to configure and, when you affirm by selecting a configuration,
the folder is created and populated.
That will happen as long as you have selected one or more plugins (see below). The C#, C++, and Rust
plugins supply configurations for debugging. You can then edit them
if you wish to modify the way debugging or builds happen.
I do all builds in the terminal, so only have a launch.json file, no tasks.json file for building.
VS Code settings are stored in three places:
-
local project settings:
Debugging settings in launch.json and build settings in tasks.json
Find in project's .vscode folder, as JSON files launch.json and tasks.json
Access by opening json file in code editor
-
user settings:
Hundreds of settings for Terminal, Keyboard mappings, ...
Find in C:\Users\[userid]\AppData\Roaming\Code\User\settings.json
Access: View -> Command Pallet -> Preferences -> Open Settings(JSON)
-
default settings:
All available settings (most of which you don't want to change)
Doesn't appear to be a physical json file.
Access: View -> Command Pallet -> Preferences -> Open Default Settings(JSON)
You can get to forms for changing preferences from Manage icon (gear) at left bottom of IDE.
Setup for Editing, Building, and Debugging Code:
VS Code, as delivered has a very good code editor, but does not have the ability to build, execute, and
debug code for the languages of interest to us here. You get those by adding plugins from the
plugin selector on the left.
Figure 2. VS Code Plugins
If you click on the plugins icon on the left border of the IDE you will see something like the
view shown in Figure 2. That shows that I have installed plugins for C++, C#, CMake, and Rust.
The C++ plugin provides intellisense for the code view and for building and debugging.
The plugin uses MsBuild, but the path to that needs to be configured, and you can't easily
configure the terminal to use MsBuild if it isn't on your path.
For that, CMake is an excellent alternative. You may wish to look at my
CMakeDemo repository for a use example.
You build the project target by running CMake in the attached terminal. Then run or debug using
the Run menu at the top of the IDE.
The C# plugin provides intellisense. You need to build your project target in
the attached terminal by issuing a "dotnet build" command. Then you can run or debug
using the Run menu.
The Rust plugin provides intellisense and the ability to build and run the
resulting executable from the Run menu. Usually I do all building in the terminal window
and run from there as well, as shown in Figure 4. I just use the VS Code run menu to start Rust debugging.
Debugging:
Figure 3. VS Code Debugging
Debugging Rust in VS Code (pdf)
One final remark: you get finer control over the debugging process by selecting the debug option
on the left border of the IDE, just above the plugin selector.
That allows you to select one of multiple debug configurations if you have them defined in
launch.json (you find that inside the .vscode folder). You also can view local variables,
set watches, and look at machine registers.
If you expand Figure 3. by clicking on the image body, you will see the debug control bar at the
top which provides controls for single stepping, step-into, step-outof, restart, and quit.
The first button on the control bar is a continue button that will move to the next available
breakpoint. You set those by clicking in the left margin of the edit window, just to the left
of the line numbers.
Platforms:
All of the above works almost identically on both Windows and Linux. I've used VS Code
on macOS, but haven't yet done much development there, but expect that all of these
observations carry over to that platform as well.
Complementing all of this with a github account makes it easy to move code between platforms,
and use virtually the same development processes on each.