Visual Studio Code Shortcuts VSCode

Jul 2nd, 2021 - written by Kimserey with .

I have been using Visual Studio Code for many years, starting from frontend development with Angular and React, then moving to work on Python and lately working on C# projects. Visual Studio Code has always been at the top of my favorite editor to use as it is very lightweight, responsive and fast. It’s quick to open files, quick to load projects, it has a clean and minimal interface and has a strong community. Over the years of using it, I realised that there are a couple of shortcuts that I keep using in repetition and that I found missing when using other IDE. In today’s post I’ll go through those keyboard shortcuts.

[Editor Shortcuts]e(#editor-shortcuts)e

Starting first with the shortcut to quickly access files, split screens or managing editor groups:

For Mac:

  • CMD+P go to file
  • CMD+P > CMD+\ go to file > open in separate editor group
  • CMD+1/2/3/n open a separate editor group or focus editor group if eexistinge
  • CTRL+1/2/3/n select file within the editors group
  • CTRL+TAB select file within groupe
  • CTRL+R change workspaces
  • CMD+B toggle side bare
  • CMD+SHIFT+E focus on file explorer on side bar, useful after doing a global search CMD+SHIFT+F and we want to focus back onto explorer
  • CTRL+CMD+F fullscreen
  • CMD+K, W closes all current windows

For Ubuntu:

  • CTRL+P go to file
  • CTRL+P > CTRL+ENTER go to file > open in separate editor group
  • CTRL+1/2/3/n open a separate editor group or focus editor group if existing
  • CTRL+1/2/3/n select file within the editors group
  • CTRL+TAB select file within group
  • CTRL+R change workspaces
  • CTRL+B toggle side bar
  • F11 fullscreen
  • CTRL+K, W closes all current windows

Terminal Shortcuts

Moving on to managing the terminal:

For Mac;

  • CTRL+ ` open terminal
  • CTRL+CMD+LEFT/RIGHT resize terminal
  • CMD+\ split terminal
  • CMD+ALT+ARROW change terminal focus (depending on terminal panel orientation)
  • To close the terminal, type exit (if you are using bash)

For Ubuntu:

  • CTRL+ ` open terminal
  • CTRL+SHIFT+LEFT/RIGHT resize terminal
  • CTRL+\ split terminal
  • ALT+ARROW change terminal focus (depending on terminal panel orientation)

Codelens Shortcuts

Then some shortcuts to work with Codelens, looking at definition, or implementation (in OOP languages):

For Mac:

  • F12 go to definition
  • CTR+- go back to previous cursor, useful when using F12
  • CTRL+SHIFT+- go forward cursor, same useful when using CTRL+-
  • ALT+F12 peek definiton
  • SHFT+F12 show all references, on types would be references within the project, on variable will be references within the scope where the variable is available
  • CMD+F12 for language like C#, go to abstraction implementation, if multiple one available show in peek

For Ubuntu:

  • F12 go to definition
  • CTRL+ALT+- go back to previous cursor, useful when using F12
  • CTRL+SHIFT+- go forward cursor
  • CTRL+SHIFT+F10 peek definiton
  • SHFT+F12 show all references, on types would be references within the project, on variable will be references within the scope where the variable is available

Problem Shortcuts

There are also problem management shortcuts, allowing us to quickly see which line of code is causing a problem:

  • CMD+SHIFT+M show problem panel
  • F8 circle through problems

Cursor Shortcuts

Lastly management of the file being edited:

For Mac:

  • CTRL+G go to specific line of code
  • CMD+K+0 fold all
  • CMD+K+J unfold all
  • CMD+K+L toggle fold
  • CMD+SHIFT+O search symbols in file
  • SHIFT+ALT+F format document
  • CMD+ALT+O organize usings
  • CMD+ALT+UP/DOWN select multiline for editing
  • CMD+D select full word

For Ubuntu:

  • CTRL+G go to specific line of code
  • CTRL+K+0 fold all
  • CTRL+K+J unfold all
  • CTRL+K+L toggle fold
  • CTRL+SHIFT+O search symbols in file
  • CTRL+SHIFT+I format document
  • CTRL+ALT+O organize usings
  • CTRL+SHIFT+UP/DOWN select multiline for editing
  • CTRL+D select full word

Custom Shortcuts for Quick Scrolling

With screens having larger and larger resolutions, we are able to display hundred lines on a monitor. Navigating down without a mouse scroll becomes a pain as to go to the middle of the screen, we would either need to hit CTRL+G > 50 to go to line 50 or hit DOWN and waiting a considerable amount of time until the cursor moves to line 50.

Another way is to setup custom keyboard bindings which would move the cursor skipping lines five by five which would accelerate the movement of the cursor to the desired line, and when we get close to line 50, we can then use the regular DOWN arrow.

This can be done by adding our own mapping via:

  • CMD+SHIFT+P > open keyboard shortcuts (JSON)

Then copy the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "cmd+up",
        "command": "cursorMove",
        "when": "textInputFocus",
        "args": {
            "to": "up",
            "by": "line",
            "value": 5
        }
    },
    {
        "key": "cmd+down",
        "command": "cursorMove",
        "when": "textInputFocus",
        "args": {
            "to": "down",
            "by": "line",
            "value": 5
        }
    }
]

This would then replace the current CMD+UP and CMD+DOWN to:

  • CMD+UP move the cursor by 5 lines up
  • CMD+DOWNmove the cursor by 5 lines down

Note that we specify "when": "textInputFocus" so that the shortcut is only available when the editor focus is on a text input.

Verifying Shortcuts

It’s also possible to verify the usage of the shortcuts via the Keyboard Shortcuts UI which allows us to record keys to find the definition of the shortcut associated with the key combination.

  • CMD+SHIFT+P > open keyboard shortcuts

vscode

And that concludes today’s post!

External Sources

Designed, built and maintained by Kimserey Lam.