VSCode Keybinds to Speed up Your Work
Visual Studio Code keyboard shortcuts to speed up the mundane task
Ever since I shifted to VSCode, I have been amazed at the rich feature set it offers. These features have made it possible for me to maintain my flow state while getting work done. Keybinds are by far my favorite feature. Paired with coding assistants like Kite, VSCode becomes the powerhouse that programmers yearn for. Here are some keybindings I find myself using all the time.
Create multiple cursors
Hold down the Alt key and click where you want the cursor to appear. This is incredibly useful while prefixing or suffixing multiple variables at the same time. It is a neat alternative to find and replace. You can take this a step further by holding down the Alt key, then dragging vertically to create cursors. This saves you multiple mouse clicks.
Select Next Occurrence
Select the text you want to search, hold Ctrl then hit D for every occurrence you want to find. Here we are finding all occurrences(8) of ‘AdmissionEx’ and replacing it with ‘AdEx’. This allows for simultaneous editing with multiple cursors.
Move Line Up/Down
Go to the line you want to move, hold Alt then press the directional arrows as many times as you want to move the line. This is especially helpful for procedural oriented languages like C, Python where the flow of the program matters. This saves the time you spend selecting the statement, deleting it then retyping it to its new position.
Fold/Unfold All
Hold Ctrl, K, 0(Zero) to fold all the foldable part of the code. This folds every section recursively. If you want to fold in levels, replace 0 with the level you want to fold. To fold only up to 2 levels, hold Ctrl+K+2. To unfold them, press Ctrl(hold)+K+J. This makes getting in and out of methods really easy.
Line Comment
- Go to the line you want to comment, press Ctrl + /. This comments out the line. Similarly, if you want to comment out multiple lines, select the lines and press Ctrl+/. I use this all the time for debugging purposes. This is by far my most used keybind after ctrl+C and ctrl+V.
- To comment out an entire folded section, select the statement that represents the section and the line below it. Now comment these out. You will notice that the section unfolds after you comment it out. This is because the section is no longer a valid piece of code but a bunch of lines that do not affect the code.
Delete Entire Line
To delete an entire line without having to select it, press Ctrl+Shift+K. Now you could just hold delete until the entire line is deleted. But where this trick shines is, it doesn't mess up the indentation like holding down delete sometimes does. This also works with multiple lines.
I highly recommend you to press Ctrl+K+S and open VSCode keybind list and get used to all the keybinds. The lesser-known keybinds.