Mac OS Recipe: Create a Shortcut for Visual Studio Code in your Terminal

I like to work with Visual Studio Code. It’s a fast and lightweight code editor and I use it on my Mac. Many a times, I would like to open or create a source code file directly from my Terminal and therefore I decided to create a shortcut for Visual Studio Code so that I could open the editor with a simple command. All I had to do was to modify my .bash_profile file which I am sharing as a recipe here:

  1. Open Terminal.
  2. Open your .bash_profile file by executing the command:
    open ~/.bash_profile
  3. Copy the following code:
    code () { VSCODE_CWD=”$PWD” open -n -b “” — args $* ;}
  4. Save the file.
  5. To let the Terminal know about this change, execute the following command:
    source ~/.bash_profile
  6. Now you can open Visual Studio Code in your Terminal anytime you want by simply typing code and pressing the Return key.