Skip to content

Instantly share code, notes, and snippets.

@elliot-nelson
Created June 1, 2021 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliot-nelson/760f1ea3e64469224cd1ea4db5e4497c to your computer and use it in GitHub Desktop.
Save elliot-nelson/760f1ea3e64469224cd1ea4db5e4497c to your computer and use it in GitHub Desktop.
Tip - Open VSCode from command line

Open VSCode from the MacOS command line

After downloading VSCode, it's probably just a binary sitting in your Downloads folder. The first thing you want to do is copy that binary into your /Applications folder. (Or open Explorer windows for both folders and just drag and drop the VSCode icon into the Applications folder.)

Next, you'll want to make a link to the VSCode app in your user binary folder. (If you don't have one, create it first and then come back.)

Double-check the location of the VSCode binary (mine is at /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code). Create a soft link to it like so:

ln -s '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code' ~/bin/code

Note: I named my link code, which is what I prefer, but you can use vscode or edit for example if you prefer that.

Now you can quickly open a new VSCode window in any folder from the command line by typing:

code .

If you want to open a specific file, VSCode will automatically open it in the "correct" VSCode window (if you've opened one for that folder). If you haven't, by default it will open the file in whatever the last VSCode editor you were using. This is convenient for just quickly editing one-off files, like your zshrc for example:

code ~/.zshrc

Happy editing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment