Opening Projects Faster with VS Code
March 15, 2018
If you are new to VS Code, here’s two quick tips that could help speed up your workflow in macOS for getting a project up and running in the editor.
Out of the box, VS Code does not offer a command line tool to allow you to open your working directory or files from the terminal. Also, macOS does not offer the right-click ‘Open With…’ menu for folders to be opened in a code editor.
How to Open a Project in VS Code From Terminal
Say you are finished setting a project up in the terminal in the directory
projects/mygreatproject and want to fire it up immediately without using the Finder. Out of the box, VS Code does not include a command line tool, but they fully support one that takes two seconds to install (these instructions come straight from their docs).
1. Launch VS Code.
2. Open the Command Palette (⇧⌘P) and type ‘shell command’ to find the Shell Command: Install ‘code’ command in PATH command.
3. Restart the terminal for the new
$PATH value to take effect. You'll be able to type 'code .' in any folder to start editing files in that folder.
Now from the terminal, you can type
code . from within the
projects/mygreatproject directory and you’re ready to work. (Note: you may also open individual files with this method and will now have access to the full VS Code command line arsenal)
How to Open a Folder in VS Code from Finder
If you are used to right-clicking files in macOS and choosing a program from the ‘Open With…’ menu, you may have noticed that is not an option for folders. There are three ways to go about fixing this, but my preference is to take advantage of a great tool Github user sozercan created called OpenInCode.
Once completed, you will have a nifty button like shown in this gif from the README:
Here are the installation instructions straight from the docs:
- Download app (if using VSCode Insiders, download this instead)
Open in Code.appto
- While holding Command(⌘) key, drag
Open in Code.appto Finder toolbar
After installation, any time you want to open a folder straight from Finder in VS Code, it’s as simple as clicking on the button in the Finder toolbar.
- Navigate to a folder you want to open with Visual Studio Code
- Click on the toolbar icon
- Folder will open with Visual Studio Code
Here’s the other two solutions and why I do not prefer them:
- Create a new ‘Service’ which will show under the ‘Services’ menu when you right-click a folder. Not a bad solution, but I prefer the option not be nested in a sub-menu after right-clicking.
- Drag and drop the folder on to the VS Code icon in the Dock. This is great as well, but still not the most ergonomic, especially if you are working with just the trackpad and no mouse.
Thanks for reading and happy VS Coding!