pic
Personal
Website

1c. VS Code (OPTIONAL)

PhD in Economics

Features and Keyboard Shortcuts

We present a few handy features and keyboard shortcuts for VS Code. Remarkably, several of them can be used regardless of the programming language you're running.

Each feature discussed includes a gif for a visual illustration. Simply click "Example" to see them in action, or alternatively press Alt+🠙 or Alt+🠛 to open and close all of them simultaneously.

To run a script

Select the script to be executed and press Ctrl+Enter
Example

To format expressions and make them more legible

Select the script to be formatted and press Ctrl+k + Ctrl+f. Sometimes, activating this tool requires running it twice.
Example

To align the equal signs

This requires the VS Code Extension "Better Align". It aligns consecutive lines by the equal sign and other symbols. It's implemented by pressing Alt + a.
Example

See also the extension "Cursor Align", which aligns code by clicking the position on each line.

To extend the cursor vertically

Hold down Alt+Ctrl + press 🠙 or 🠛
Example

To see the documentation of a function

Hover over the function
Example

Alternatively, you can go the REPL, press ?, and then type the function's name you want to search for.
Example

To autocomplete a word

Start typing a word + press Tab when you see the option list
Example

To introduce unicode characters (Tab Completion)

Type a unicode character/command, press Ctrl + Space to open an option list, and then choose the option and press Tab
Example

In Julia, Greek letters and math follow the syntax of Latex. Thus, they start with \ (e.g., \eq for ≠). Tab completion can also be used at the REPL, even if you don't use VS Code. Nonetheless, you won't be able to choose from a list of options.

To select the same word multiple times

Select the word and then press Ctrl+d for selecting each additional time it appears. This is useful when you want to change part of the expression.
Example

To hide part of the script

Given a code block, add #region at the beginning and #endregion at the end.
Example


When you have several lines indented, VS Code allows you to hide the block automatically. The following example shows this for a function.
Example

To turn multiple lines into a comment

Select all the lines you want to interpret as a comment rather than code. Then, press Ctrl + /
Example