When listening to the Syntax podcast episode on VSCode, using keyboard shortcuts came up. That inspired me to dig a little deeper and write about it!
When you spend a lot of time with text, moving around and manipulating that text takes up time that adds up quickly. Keyboard shorcuts go a long way in speeding up your text-related workflow.
I'm not advocating for ditching your mouse entirely.
Spend some time learning how to do operations you often repeat by using keyboard shortcuts instead of your mouse. The investment you make now will be paid back tenfold in no time.
I wish someone told me to get really comfortable with these when I started learning how to code. They are not talked about often, because many people consider them too basic. I was used to navigating text a single character at a time with the arrow keys. Knowing about most of these shortcuts didn't translate into using them, I was still using my mouse out of habit for most of these operations until recently. Using these until you can activate them from muscle memory will save you a lot of time.
Mac users: substitute ctrl for command
ctrl key pressed to affect words instead of characters.
ctrl+leftMove cursor to the beginning of the previous word.
ctrl+rightMove cursor to the beginning of the next word.
homeMove cursor to the beginning of the line.
endMove cursor to the end of the line.
ctrl+homeMove cursor to the beginning of the file.
ctrl+endMove cursor to the end of the file.
ctrl+backspaceErase previous word.
ctrl+delErase next word.
shift to select while your cursor moves.
shift+up/downMove cursor line up/down and select everything in between
shift+home/endSelect till beginning/end of line
You can use the shortcuts above nearly everywhere. The next ones are more specific to the code editor.
The shortcuts listed here are the default ones, they might be different for you.
I'm using VSCode(on Windows), but many of them are also available in other editors. You can view your keyboard shortcuts in VSCode by opening the command palette (
ctrl+shift+p) and choosing "Preferences: open keyboard shortcuts". Here you can search for and edit every keyboard shortcut for VSCode.
What follows are the ones I use frequently.
Moving/copying a line up or down. (sick name @wesbos)
alt+up/downmoves your current line.
shift+alt+up/downduplicates your current line.
NOTE: You don't have to select the entire line for these to work.
Expand/shrink your selection to the next logical point
alt+shift+rightexpands the selection.
alt+shift+leftshrinks the selection.
Renaming a function/variable/... can be a chore, you don't want to miss a single instance, it could break your whole project and make puppies sad!
F2rename the highlighted symbol.
ctrl+dAdd selection to next find match. Selects the next matching text when you have text selected. Selects the next matching symbol when your cursor is in one.
ctrl+:on azerty-keyboards) Toggle comment(s) for the current line/lines.
ctrl+lSelect the current line.
ctrl+shift+kDelete the current line.
ctrl+enterInsert line below.
ctrl+shift+enterInsert line above. Useful when your caret is in the middle of a line.
ctrl+`Toggle the integrated terminal. (
ctrl+bToggle sidebar visibility.
A great feature many might know from Sublime Text.
Access available commands based on your current context. If you forget some shortcuts, don't worry. This feature has your back and will show the shortcut next to the command. I really like driving
git from here.
Quickly search for and open a file.
Since writing, VSCode introduced new features surrounding this. The shortcuts below should still work, but I encourage you to check out their release notes for more info.
Editor groups are what you might refer to as windows within the main VSCode window. They can hold a group of items (tabs).
You can immediately open a new file in a new editor group. This works from the sidebar, or from the quick-open feature.
ctrl+tabopen next recently used tab in this editor group
ctrl+shift+tabopen previous recently used tab in this editor group
You can change the currently focussed editor group with
ctrl and the number keys
Move the editor to the previous/next group by using
ctrl/alt and the arrow keys.
I'm sure I left out a lot of your favorites, please let me know about them!