Launching VSCode from the Command Line in MacOS

Launching VSCode from the Command Line in MacOS

While getting hands on with Terraform and doing a bit of learning about it (blog posts to come!), I found a neat trick to opening a specified file with VSCode using the MacOS command line.

While it initially didn't seem very helpful to me, I've found this new method of using VSCode to be very intuitive.  Rather than having to manually seek out a file in the VSCode GUI, I can simply use it as if it were a traditional text editor, such as VIM.

Here's how to get the same setup on your machine.


To start, open up your installation of VSCode and enable the command palette with the key combo of Cmd + Shift + P.

Next, you will need to populate the command palette with >shell command and choose the bottom option displayed in the image above to install the code command.  You will most likely be prompted to then enter your device credentials for installation purposes..

After doing so, you should be presented with a window alerting you that the shell command has successfully been installed. Let's test it out!


Now that we have code installed as a shell command, we can use it as we would with a regular command line text editor, such as Nano or VIM. To test code's functionality, try to edit a file with it by using code name_of_file.

With that simple command, VSCode will immediately open up, displaying the file you requested.


While I typically live in VIM for my text editing needs, VSCode occasionally comes in handy.  With the addition of the code command, I can now use the application even more efficiently within my workflow.