Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"code ." Not working in Command Line for Visual Studio Code on OSX/Mac

The command code . doesn't work in this manual.

All the other steps before that worked. How can I call the Visual Studio Code in an OS X terminal?

pwd

/Users/mona/nodejs/myExpressApp

code .

-bash: code: command not found


I ended up opening it from within Visual Code Studio by changing the workspace, but why won't that command code . part work?

Enter image description here

like image 619
Mona Jalal Avatar asked Apr 29 '15 22:04

Mona Jalal


People also ask

How do I run code in Terminal VS Code Mac?

You can also run VS Code from the terminal by typing 'code' after adding it to the path: Launch VS Code. Open the Command Palette (Cmd+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.

Why my code is not running in terminal in VS Code?

Changing Default Command Line Shell Then, click on the arrow on the side of a plus (+). Here, choose Select Default Profile. Then, select any other type of command line shell. Then, restart vs code and try working on terminal.


3 Answers

1. Make sure you drag the Visual Studio Code application into the Applications folder

Otherwise (as noted in the comments), you'll have to go through this process again after a reboot.


2. Next, open Visual Studio Code

Open the Command Palette via + + P and type shell command to find the Shell Command:

Use the Uninstall 'code' command in the PATH command before the "Install 'code' command in PATH" command.

![Command Palette

After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder. The "." Simply means "current directory"

(Source: Visual Studio Code documentation)


Note: If you're running a build based off the OSS repository, you will need to run code-oss . (Dzeimsas Zvirblis' comment)

like image 83
Mark Pieszak - Trilon.io Avatar answered Oct 06 '22 05:10

Mark Pieszak - Trilon.io


If you want to add it permanently:

Add this to your ~/.bash_profile, or to ~/.zshrc if you are running macOS v10.15 (Catalina) or later.

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Source: Visual Studio Code on macOS

like image 24
Ryan Efendy Avatar answered Oct 06 '22 05:10

Ryan Efendy


Open the ~/.bashrc file using vi or Vim:

vi ~/.bashrc

Enter the following by pressing i to insert:

code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

Save the file using :wq

Reflect the settings in ~/.bashrc using the following command:

source ~/.bashrc
like image 59
Suhail Taj Avatar answered Oct 06 '22 05:10

Suhail Taj