pic pic
Personal
Website

1c. VS Code (OPTIONAL)

PhD in Economics

Features and Keyboard Shortcuts

We present a few keyboard shortcuts and some handy features for VS Code. They also apply to its privacy-focused alternative VS Codium. Remarkably, these features are largely language-agnostic, holding regardless of the programming language you're working with.

For visual illustration, each feature discussed is accompanied by a GIF. To view these GIFs, simply click "Example", or alternatively press Alt+🠙 or Alt+🠛 to open and close all of them simultaneously.

For more information about how to use Julia with VS Code, see the official guide.

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, you must run the command twice to activate the tool.
Example

To align equal signs

This feature requires a VS Code Extension called "Better Align". It aligns consecutive lines by using the equals sign and other symbols as a reference. It's implemented by pressing Alt + a.
Example

See also the extension "Cursor Align", which aligns code according to the position indicated on each line.

To extend the cursor vertically

Hold down Alt+Ctrl and press 🠙 or 🠛
Example

To see the documentation of a function

It requires hovering over the function.
Example


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

To autocomplete a word

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

To introduce unicode characters (Tab Completion)

Type a unicode character, press Ctrl + Space to open an option list, choose an option, and press Tab.
Example


Unicode characters include Greek letters and math symbols. They can be introduced by using the same syntax as in Latex. To add them, you need to start the word with \ (e.g., \eq for ≠) and use Tab completion.

To select the same word multiple times

Select the word and then press Ctrl+d for selecting the next occurrence of the word.
Example

To hide part of the script

Enclose a code block by adding #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 possibility with a function.
Example

To turn multiple lines into a comment

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