pic
Personal
Website

1c. VS Code (OPTIONAL)

PhD in Economics

Features and Keyboard Shortcuts

We present a few keyboard shortcuts and 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, the features discussed are accompanied by GIFs. To view these GIFs, simply click "Example", 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 equal signs

This feature requires the VS Code Extension "Better Align". It aligns consecutive lines by using the equal sign and other symbols as a reference. 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

It requires hovering 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 have the same syntax as Latex. To add them, you need to start 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 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