This is the second entry in an on-going series on keyboard shortcuts in Visual Studio Code. Read part 1 here.
The further along I get in my software engineering journey, the more I appreciate the productivity afforded by mastery of my text editor’s keyboard shortcuts. For me, the text editor of choice is Microsoft’s VS Code. I feel that being able to efficiently navigate and manipulate my project files without the need for the mouse allows me to increase the speed at which I can accomplish tasks. Additionally, having to spend less time figuring out how to accomplish certain functions, or navigating to them via the menus, affords me more time to focus on writing clean and managable code. Here are today’s keyboard shortcut tips for productivity:
Rename F2
Need to rename a file? Simply selected it in the explorer pane and hit the keyboard shortcut to begin the renaming proces. Upon hitting the shortcut, it will automatically highlight the existing name, so you can begin typing immediately to replace the entire existing name, or navigate to necessary location in the filename to edit according. This will work even if the file is currently open in the editor pane. However, the power of the rename isn’t limited to the filename. If you select a variable or function name and use the same shortcut, you will have the same functionality, and it will rename all occurances of said function or variable name.
Select Everything from Cursor to Beginning or End Ctrl + Shift + Home/End
Need to select large sections of code from the beginning or end of a file, either for deletion, copying, or other purpose? Simply navigate your cursor to one end of the block to be selected, then hit the keyboard shortcut then either home to select to the beginning of the file, or end to select to the end. I use this particular shortcut often when refactoring my code and bring functionality out of one file into another.
Delete Entire Word Ctrl + Backspace
Another great timesaver, hitting this keyboard shortcut while the cursor is located at the end of the word will delete the entire word. This saves many keystrokes, especially when deleting long variable and or function names. This can also be chained together multiple times to quickly delete an entire line without having to remove your hand from the keyboard for manipulating the mouse, or mashing/holding the backspace key for several seconds.
Duplicate Line(s) Shift + Alt + Up/Down
While similar to doing a copy/paste, I find this particular shortcut to be just a fraction faster if the paste location is either immediately before or after the line(s) you are looking to duplicate. Select the line(s) you wish to duplicate, then hit the keyboard shortcut with either up or down to place the duplication before or after, respectively, the current selection.
Be sure to check back next week for even more Visual Studio Code shortcuts and productivity tips.