Streamline Your Coding Experience with Visual Studio Code Shortcuts
As a programmer, I’ve always been frustrated with the constant need to switch between my keyboard and mouse when working in Visual Studio Code (VSC). Recently, I decided to take the plunge and learn how to navigate VSC using only my keyboard. The result? A significant boost in productivity and a more seamless coding experience.
Splitting and Focusing
When working on a project, it’s common to split your IDE into multiple views to quickly switch between files. To split the editor, simply use ctrl + \
(or ⌘ + \
on a Mac). You can then switch between views using ctrl + 1
(or ⌘ + 1
), ctrl + 2
(or ⌘ + 2
), and so on. Alternatively, use ctrl + page up
/ page down
(or ⌘ + page up
/ page down
) to switch between tabs.
Focusing on the Explorer Panel
To focus on the explorer panel without touching your mouse, use ctrl + 0
(or ⌘ + 0
). You can then navigate the panel using the up and down arrows, and open a selected folder or file with the enter key.
Alternative Approaches
If you need to select files that are farther down the list, try using ctrl + p
(or ⌘ + p
) to open a search bar. You can then type in a filename or full path to quickly find what you’re looking for.
File History
The file history feature in VSC saves your recently opened files, allowing you to quickly switch between them. Use ctrl + tab
to switch between the last opened files, or alt + left
/ right arrows
(or ctrl + shift + -
/ ctrl + -
) to switch directly to the previous/next file in the file history.
Traversing Code
Now that we’ve covered file navigation, let’s dive into code traversal. One powerful feature in VSC is the outline, which allows you to see a high-level view of your code. Use ctrl + shift + o
(or ⌘ + shift + o
) to bring up the command palette, where you can choose the part of the outline you’d like to jump to.
Jumping to a Specific Line
If you need to jump to a specific line in your code, use ctrl + g
. You can also use ctrl + u
(or ⌘ + u
) to jump back to where you were before.
Definitions and References
VSC has several shortcuts for working with definitions and references. Use F12
to jump to the definition of a function or variable, or alt + F12
(or option + F12
) to peek at the implementation. You can also use shift + F12
(or ⌘ + k and F12
) to peek at references.
Changing Symbol Names
If you need to change the name of a symbol throughout your project, use F2
. This will prompt a window where you can type in the new name, and VSC will replace all occurrences.
Error Handling
When there’s an error in your code, VSC underlines it with a red line. Use F8
to quickly see what’s wrong, and press esc
to leave “error mode.”
IntelliSense Hover
To see the simplified definition of a symbol, use alt + shift + s
(or your preferred shortcut). You can set up your own shortcuts by using ctrl + k
(or ⌘ + k
) and then ctrl + s
(or ⌘ + s
).
Showing Recommended Actions
VSC often suggests fixes for your code, such as importing missing modules or removing unused code. Use ctrl +.
(or ⌘ +.
) to see available actions for the currently highlighted code.
Selecting Code
To select code based on scope, use alt + shift + left
/ right
(or ⌘ + ctrl + shift + left
/ right
). Repeated use of this shortcut will make the selection bigger or smaller.
Integrated Terminal
VSC’s integrated terminal allows you to have a terminal right next to your code. Use ctrl +
(or ⌘ +
) to open a terminal, and ctrl + shift + 5
to split it into panels. You can then focus on a terminal using ctrl +
(or ⌘ +
), and switch between split panels using alt + left
/ right
(or ⌘ + option + left
/ right
).
Bonus Terminal Shortcuts
To kill a terminal, set up a shortcut for “workbench.action.terminal.kill” in the shortcuts settings. I use ctrl + shift + x
. You can also maximize a terminal by setting up a shortcut for “workbench.action.toggleMaximizedPanel”. I use ctrl + shift + q
.
Mastering Shortcuts
The key to mastering these shortcuts is consistency. Try to implement them gradually, and before you know it, you’ll find yourself relying less and less on your mouse, making your coding experience much smoother and more efficient.