Sometimes we have to write the same thing at multiple places, we can do that in VS Code by using multiple cursors. Just press
alt + left mouse click.
#6 Add cursor above/below in VS Code
Now that I have told you about adding multiple cursors, we can take this one step further. Let’s say you have to add same thing in adjacent lines, then you can use
ctrl + alt + up/down arrow key.
#7 Add multiple cursors in VS Code (find-and-replace way)
This is possibly my favorite method. If you have a word highlighted, you can select the next occurrence of that word by pressing
Ctrl + d, then repeat until you have all instances of the word selected.
Alternately, you can add a cursor to all occurrences of the current selection with
Ctrl + Shift + L. Then, you just type the replacement, and all instances are updated with each keystroke!
In few cases, you might end up selecting one or more instances of the desired word or phrase. Luckily,
Ctrl + u will undo the last multi-cursor operation. This will prevent you from starting all over, which is especially helpful when you are selecting a lot of instances.
While you can use the regular find-and-replace dialog, but I find this much more convenient and intuitive.
#8 Move line up/down in VS Code
Moving a line up or down is useful literally every 10 minutes while you use VS Code, right? Generally people cut the whole line, and then place the cursor in the above line, and then paste it. You can do this at once by
Alt + Up Arrow to move up and
Alt + Down Arrow to move down.
#9 Duplicate line in VS Code
A very powerful and known feature is the ability to duplicate lines. Simply press
Shift + Alt + Up/Down Arrow.
#10 Go to last edit location in VS Code
Sometimes when I write the code, I need to pause a bit and go to different files to check other things. And after that, I need to quickly go back to the place where I was editing. This shortcut makes the move so easy.
VS Code Keyboard shortcut –
ctrl + K ctrl + Q
#11 Go to bracket in VS Code
Sometimes I want to quickly go to the end of a block to add some new code, and I can put the cursor on the opening bracket and type
Ctrl + Shift + \ to jump to the closing bracket.