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.
Starting first with the shortcut to quickly access files, split screens or managing editor groups:
For Mac:
CMD+P
go to fileCMD+P > CMD+\
go to file > open in separate editor groupCMD+1/2/3/n
open a separate editor group or focus editor group if eexistingeCTRL+1/2/3/n
select file within the editors groupCTRL+TAB
select file within groupeCTRL+R
change workspacesCMD+B
toggle side bareCMD+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 explorerCTRL+CMD+F
fullscreenCMD+K, W
closes all current windowsFor Ubuntu:
CTRL+P
go to fileCTRL+P > CTRL+ENTER
go to file > open in separate editor groupCTRL+1/2/3/n
open a separate editor group or focus editor group if existingCTRL+1/2/3/n
select file within the editors groupCTRL+TAB
select file within groupCTRL+R
change workspacesCTRL+B
toggle side barF11
fullscreenCTRL+K, W
closes all current windowsMoving on to managing the terminal:
For Mac;
CTRL+
` open terminalCTRL+CMD+LEFT/RIGHT
resize terminalCMD+\
split terminalCMD+ALT+ARROW
change terminal focus (depending on terminal panel orientation)exit
(if you are using bash)For Ubuntu:
CTRL+
` open terminalCTRL+SHIFT+LEFT/RIGHT
resize terminalCTRL+\
split terminalALT+ARROW
change terminal focus (depending on terminal panel orientation)Then some shortcuts to work with Codelens, looking at definition, or implementation (in OOP languages):
For Mac:
F12
go to definitionCTR+-
go back to previous cursor, useful when using F12
CTRL+SHIFT+-
go forward cursor, same useful when using CTRL+-
ALT+F12
peek definitonSHFT+F12
show all references, on types would be references within the project, on variable will be references within the scope where the variable is availableCMD+F12
for language like C#, go to abstraction implementation, if multiple one available show in peekFor Ubuntu:
F12
go to definitionCTRL+ALT+-
go back to previous cursor, useful when using F12
CTRL+SHIFT+-
go forward cursorCTRL+SHIFT+F10
peek definitonSHFT+F12
show all references, on types would be references within the project, on variable will be references within the scope where the variable is availableThere are also problem management shortcuts, allowing us to quickly see which line of code is causing a problem:
CMD+SHIFT+M
show problem panelF8
circle through problemsLastly management of the file being edited:
For Mac:
CTRL+G
go to specific line of codeCMD+K+0
fold allCMD+K+J
unfold allCMD+K+L
toggle foldCMD+SHIFT+O
search symbols in fileSHIFT+ALT+F
format documentCMD+ALT+O
organize usingsCMD+ALT+UP/DOWN
select multiline for editingCMD+D
select full wordFor Ubuntu:
CTRL+G
go to specific line of codeCTRL+K+0
fold allCTRL+K+J
unfold allCTRL+K+L
toggle foldCTRL+SHIFT+O
search symbols in fileCTRL+SHIFT+I
format documentCTRL+ALT+O
organize usingsCTRL+SHIFT+UP/DOWN
select multiline for editingCTRL+D
select full wordWith 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 upCMD+DOWN
move the cursor by 5 lines downNote that we specify "when": "textInputFocus"
so that the shortcut is only available when the editor focus is on a text input.
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
And that concludes today’s post!