How to open a new project in the same VS Code window (#tilPost)

I have many aliases and shell shortcuts defined in my dotfiles. Generally, my setup works well, and I rarely tweak it or add new aliases.
But today’s the day to add a new command alias!
If you’re a VS Code user, you can set up and u…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I have many aliases and shell shortcuts defined in my dotfiles. Generally, my setup works well, and I rarely tweak it or add new aliases.

But today's the day to add a new command alias!

If you're a VS Code user, you can set up and use the code CLI command to open files/folders, diff files, or merge stuff. It's pretty neat, but I really just use it to open projects. Nothing fancy.

# In the morning ...
cd ~/projects/project-a
code .

# After lunch ...
cd ~/projects/project-b
code .

# you get the idea ...

There's nothing particularly wrong with this workflow except that code will open a new VS Code window whenever you call it. If you don't close the previous window, you'll open more and more editors. The more projects you have, the more coding windows you have to juggle (or close).

During a typical workday, I quickly reach six or more open editor windows (because, of course, I don't close the windows and just fire up another code command). Only after reading Nick Taylors' "One Tip a Week" newsletter I realized how much all these windows annoy me.

Nick, of course, had a solution: code -r. That's it!

The -r option will make VS Code open a new project and reuse the open window. No more new windows!

But of course, nobody wants to type the -r option all the time, so here's my new alias following Nick's recommendation:

# reuse the existing window instead of opening another one
alias c="code -r"

And let me tell you, this alias (👇) already made it into my muscle memory.

# In the morning ...
cd ~/projects/project-a
c .

# After lunch ...
cd ~/projects/project-a
c .

Thanks, Nick!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2025-01-20T23:00:00+00:00) How to open a new project in the same VS Code window (#tilPost). Retrieved from https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/

MLA
" » How to open a new project in the same VS Code window (#tilPost)." Stefan Judis | Sciencx - Monday January 20, 2025, https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/
HARVARD
Stefan Judis | Sciencx Monday January 20, 2025 » How to open a new project in the same VS Code window (#tilPost)., viewed ,<https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » How to open a new project in the same VS Code window (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/
CHICAGO
" » How to open a new project in the same VS Code window (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/
IEEE
" » How to open a new project in the same VS Code window (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/. [Accessed: ]
rf:citation
» How to open a new project in the same VS Code window (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2025/01/20/how-to-open-a-new-project-in-the-same-vs-code-window-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.