Mike Slinn
Mike Slinn

Microsoft Visual Studio Code Notes

Published 2021-03-22. Last modified 2021-03-26.
Time to read: about 3 minutes.

This article is categorized under Python, Visual Studio Code.

Useful Default Key Bindings

Ctrl+K   Ctrl+S
Display / edit the Keyboard Shortcuts definitions.
You can filter the keybindings by pressing Alt+K or clicking the icon of the little keyboard at the top right of the Keyboard Shortcut page, then press the keys that you want to see the key binding for. The keyboard icon starts keystroke recording mode. Recording mode is sticky; each time you revisit the Keyboard Shortcuts tab you can just press the keys you are interested in to see their bindings. Step by step:
  1. When you press the Ctrl key you will see "ctrl" displayed, and recording mode continues to listen to what you type. Don't do this right now, but FYI, if you toggle keystroke recording mode now, and then remove the quotes around "ctrl", you will see a sorted list of all the key chords bound to Ctrl.
  2. Next, when you add the Shift key to the key chord, you then see "ctrl+shift" displayed. Don't do this right now, but FYI, if you toggle keystroke recording mode now, and then remove the quotes, you will see a sorted list of all the key chords bound to Ctrl+Shift.
  3. Finally, adding the = key to the key chord shows all the commands bound to Ctrl+Shift+=.
Ctrl+K+0 (zero)
Completely fold the active editor contents.
Ctrl+K+1 (one)
Fold level 1 the active editor contents.
Ctrl+K+2
Fold level 2 the active editor contents.
Ctrl+B
Toggle side bar visibility.
Ctrl+P
Show names of recently opened tabs, which might contain files to edit, or might be VSCode settings, or VSCode key bindings, etc. Click on a tab name to open it. This key binding is bound to Go to File, which is slightly logical but a not a good descriptive name.
Ctrl+Shift+P
Open the Command Palette.
Ctrl+L   G
Open the active (currently edited) file on GitHub in the default web browser. Requires the Open in GitHub extension.
Ctrl+, (comma)
Open the Settings tab.
Ctrl+Shift+T
Reopen the most recently closed editor tab.
Alt+Shift+F
Format the current file.

Annoying Side Bar Auto Reveal

Problem

When editing a file, if you Ctrl+click on a function, method or class name defined in a dependency, the dependency's folder will be expanded in the side bar. Some dependencies are deeply nested, which means that the side bar expands quite a lot. In order to close the folders in the side bar it is necessary to go all the way back to the top of that folder, which is annoying and wastes time.

Solution

In settings, look for Explorer: Auto Reveal, which controls whether the explorer should automatically reveal and select files when opening them.

To do that, bring up settings with Ctrl+, (comma), and then type reveal ex into the filter.

The default value is true. Change the value to false.

Bonus: Reveal Active File in Side Bar

To scroll to a file that you are editing in the list of files in the side bar, right-click on the file's tab, then select Reveal in side bar.

Even better, define a keyboard shortcut to do this:

  1. Bring up the Keyboard Shortcuts definitions by typing Ctrl+K   Ctrl+S.
  2. Type reveal side into the search bar.
  3. Double-click on File: Reveal Active File in Side Bar.
  4. For my desired key shortcut, I pressed Ctrl+Shift+Alt+R, then pressed Enter.

Plugins