DEV Community

Cover image for VS Code Shortcuts That I Would Teach Myself if I Had a Time Machine With Limited Fuel

VS Code Shortcuts That I Would Teach Myself if I Had a Time Machine With Limited Fuel

Vitor Paladini on July 22, 2020

— "Hey, it's me. Listen up, I don't have much time." — "Wait, what?! What is happening?! Who are-How did you get in my house?! Wh-why do you look ...
Collapse
 
paulasantamaria profile image
Paula Santamaría

Best "vscode shortcuts" post I've ever read. Extra points for the b99 reference.
Next time you go back make sure to teach your past self this one: Shift +Alt + F. It will automatically format your code (if you have a formatter installed for that language).

Collapse
 
diogosouza profile image
Diogo Souza

This one is really useful. The Mac version is Option + Shift + F

Collapse
 
vtrpldn profile image
Vitor Paladini

Thanks, Paula. Glad that someone caught that 😄

Shift + Alt + F is also pretty great, thanks for sharing!

Collapse
 
maxime216 profile image
maxime216

You can also configure VSCode to run this onSave as instance which allow you to dont forget formatting ;)

Thread Thread
 
paulasantamaria profile image
Paula Santamaría

Love this idea, thanks!

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan • Edited

My favorites:

  • Ctrl+L. Highlight the current line. Press it N times to highlight the next N lines.
  • Alt+Up/Down. Move an entire line of code (or the current selection) up/down. No more cutting/pasting.
Collapse
 
pzelnip profile image
Adam Parkin

The move line up/down is like my #1 used hotkey.

The other one I use a lot that's similar is SHIFT+ALT+up/down for duplicating the current line above or below.

Collapse
 
pavelloz profile image
Paweł Kowalski

I find "move line up/down" shortcut very useful.
Also cmd+a (beginning of the line) and cmd+e (end of line) very useful - not only in vscode, just in general, including terminal.

Collapse
 
drew_mc profile image
Drew McConville

Great one! (fyi this was Ctrl+A/E on mac for me)

Collapse
 
milhod profile image
Milho

Do you know how long I tried to find this info? Thank you! Lot of my time will be saved

Collapse
 
pavelloz profile image
Paweł Kowalski

Glad i could help :-))

Collapse
 
vtrpldn profile image
Vitor Paladini • Edited

Man, I kid you not, that was literally my expression when I tried your suggestion.

amazed

Fantastic, never even knew that this kind of navigation was possible.

Collapse
 
bytejunkie profile image
matt short

can't see this one mentioned elsewhere, but i must use it every hour.

CTRL + / >> comment/uncomment a line or selection

also mentioned elsewhere, but different

CTRL + ' >> open a terminal window (but this one is apostrophe, not backtick)

Collapse
 
cyberhck profile image
Nishchal Gautam

I use forward and backward button on my mouse

Collapse
 
maxime216 profile image
maxime216 • Edited

Good article that will probably help many people :)
Well, some other things that are usefull =>
(Sry Idk for windows)
Command + d : select current word (really essential shortcut) and, if you press it again, it will select the next occurence of this word :)
And an other one which allow you to work on several line at the same time:
Command + option + arrow (up or down), then do what you want with your selected lines (esc to leave this mode !)

Collapse
 
mdhesari profile image
Mohammad Fazel • Edited

So creative and perfect article!

Thank you for sharing it.

What I use every day is opening and closing terminal :

Command/Ctrl + backtick
Command/Ctrl + shift + backtick

Collapse
 
vtrpldn profile image
Vitor Paladini

Command/Ctrl + backtick is toggle Integrated Terminal and Command/Ctrl + shift + backtick creates a new one, right? Thanks for sharing!

Collapse
 
mdhesari profile image
Mohammad Fazel

👌👌

Collapse
 
waseidev profile image
Walther Seidel

in spanish keyboards is:
Ctrl + ñ" (open/closes a terminal)
"Ctrl + Shift + ñ" (open an additional terminal)

Collapse
 
rajatkantinandi profile image
Rajat Kanti Nandi

If you are on mac with touchbar you can also press the arrow keys in the touchbar. Super convenient.

Collapse
 
vasilevas profile image
Radu Pacurar Vasile

Nice post and nice replies. I'll also add some shortcuts I'm using and I didn't see here.

  1. Select several lines. SHIFT+ALT+i will create multicursor. Then CMD+LEFT/RIGHT to go to the beginning/end of the lines.
  2. CMD+P. Then > to see the latest command, or : to jump to specific line. For example, if I have some text I want to uppercase it, I select the text, CMD+P, then type > and start typing uppercase. You will see a Transform to Uppercase command :)
Collapse
 
cben profile image
Beni Cherniavsky-Paskin

Alt+1, Alt+2, Alt+3 ... also work for focusing tabs. It also works in Chrome (both Ctrl+digits and Alt+digits), Firefox (only Alt+digits) and gnome-terminal (only Alt+digits), making this the one shortcut to remember! [Linux]

Collapse
 
leob profile image
leob • Edited

Control-Shift-P (or Command-Shift-P) is the "master key" which shows your most recent commands, and allows you to search for any other command, including keyboard shortcuts - learn this one first, and then gradually you'll learn the rest ...

Control-Q is also one I use a lot - switching between the Explorer view, the Source Control view and the Debug/Run view.

Ah and then Control-] or Cmd-] (on OSX) to jump to end bracket/begin bracket is a powerful one.

Collapse
 
mmanousos profile image
Melissa Manousos

CMD + ] on my Mac causes the line to indent (like using TAB) rather than jumping to brackets. I wonder if you have mapped your hot keys differently.

Collapse
 
leob profile image
leob

Ah yes maybe I remapped it, some key combos are unintuitive or conflict with other things so then I'd remap them.

Collapse
 
phongduong profile image
Phong Duong

In my vscode, I use Ctrl+Tab to navigate between tabs

Collapse
 
mehtanilay10 profile image
Nilay Mehta

My favorite is Ctrl + D to select Next occurrence. And hold ctrl key for using multi cursor.

Collapse
 
giologist profile image
Gio

This is a great list! I Found myself referring back to this after reading it a few days ago :)

Quick observation:

Command/Ctrl+W closes the current tab, Command/Ctrl+Shift+T reopens it"

For me (I've made no edits that I can recall) this closes all "except" the current tab. And then pressing it again re-opens all. Did you customize this setting?

Collapse
 
mmanousos profile image
Melissa Manousos • Edited

That seems like specialized behavior, @Gio.
The default on VSCode (as well as most browsers and operating systems) is that CMD + W closes the current window.

Collapse
 
andrematias profile image
André Matias

Awesome Post, I had fun now :)

Collapse
 
samuelabreu profile image
Samuel Abreu

My fav is Ctrl/cmd + r, to list/filter functions

Collapse
 
srgk26 profile image
S R Gokul Krishnan

You should've asked, "why am I still coding in an era where time machines exist?"

Collapse
 
vtrpldn profile image
Vitor Paladini

Well, somebody must have worked on the time machine firmware hahaha

Collapse
 
kelseyleftwich profile image
Kelsey Leftwich

I found this helpful and very funny. :)

P.S. I think the gif under "Use Command/Ctrl+Shift+L" is the gif from "Command/Ctrl+Shift+H"

Collapse
 
vtrpldn profile image
Vitor Paladini

Oh, good catch. Thanks, Kelsey! It was very fun to write as well, glad you liked it 😄

Collapse
 
theoparis profile image
Theo Paris • Edited

Is there a shortcut for creating a new file in the explorer SIDEBAR? I always have to right click first and then use my mouse to do this.

Collapse
 
shanerobinson profile image
Shane Robinson

Funny and so helpful! Thank you and thanks to all the add'l added in the comments! I have a lot of muscle memory learnin' to do.

Collapse
 
vtrpldn profile image
Vitor Paladini

Thanks, Shane! I'm very happy with all the comments, I learned quite a few new shortcuts as well 😄

Collapse
 
tranxuanthang profile image
tranxuanthang • Edited

I would rather tell my past self to learn Vim at the age 14. I use VSCode sometimes so it's still good to learn some nice commands though!

Collapse
 
nomade55 profile image
Lucas G. Terracino

Awesome post Vitor, truly a good selection of shortcuts showcased here.!

Collapse
 
sharmarajdaksh profile image
Dakshraj Sharma

I didn't even know I needed these. Thank you so much.

Collapse
 
vtrpldn profile image
Vitor Paladini

Happy to help!

Collapse
 
idanizi profile image
Idan Izicovich

Nice!!

Collapse
 
japanesemayonnaise profile image
Shimba

You are so funny. Thank you for this!

Collapse
 
vtrpldn profile image
Vitor Paladini

You're welcome, Elliot 😄

I wish I could write like this every time but I have to be particularly inspired to come up with something this silly haha

Collapse
 
lucassseverino profile image
Lucas Severino

I had a good laugh at this hahaha
Very helpful!! =)