Helpful Visual Studio Code Keyboard Shortcuts - Part 3

Posted by Kristian Joos on October 11, 2021

This is the third entry in an on-going series on keyboard shortcuts in Visual Studio Code. Read part 1 here.

One of the many ways to improve your productivity as a software engineer is to master your development environment. This can include adding keyboard shortcuts to your arsenal that increase the speed at which you edit code, enabling you to spend less time slogging through the editing process, and freeing up more time for thinking and developing solutions. Here are this weeks’ keyboard shortcut productivity tips for Visual Studio Code:

Resize Selection Shift + Alt + Left/Right Arrow

This keyboard shortcut enables you to adjust the size of your current selection (highlight) without having to use the mouse. Simply hold the Shift and Alt keys then hit the left or right arrow to grow/shrink your selection. However, this does not merely move the selection character by character, but rather it will intelligently identify code block boundaries within your code and jump from boundary to boundary, allowing you to rapidly select blocks of code for various purposes.

Move Selection Up/Down Alt + Up/Down Arrow

Have a line of code that is needed, but isn’t quite in the right place? Maybe you need to re-order a couple of function calls. You could cut and paste lines as needed, but this method is even faster. Select (highlight) the line you wish to move and hold Alt while hitting the up/down arrows. This will move your selected line up/down one line for each keystroke.

Toggle Between Opening/Closing Curly Braces {} *Ctrl + Shift + *

Need to quickly jump back to the beginning of a very long function? Or perhaps you need the reverse and need to jump to the end to quickly insert a small edit. This keyboard shortcut will allow you to jump between an opening ({) and its corresponding closing (}) curly brace, or vice versa. Make sure your cursor is either immediately before or after the current curly brace, and hit the keyboard shortcut to instantly jump to the other end of the block at the corresponding curly brace.

Comment/Uncomment Every Line in Selection Ctrl + /

This is one that I can’t stress enough the value of. Ever need to quickly comment out a block of code while attempting to debug something? Then once you’ve figured out the issue, you want to take the existing comment block and switch it back to code? Select the code block in question and hit the keyboard shortcut, and voila you have commented/uncommented the entire selection.

Be sure to check back next week for even more Visual Studio Code shortcuts and productivity tips.