Sometime you want to open a specific file from your command line easily into VS Code, but when entering code myfile.js
in your terminal you will get an error :
$ code myfile.js zsh: command not found: code
To solve that, simply open VS Code (work on MacOS, Linux and Windows) and hit the F1
button.
For MacOS user, you’ll may need to use
Fn + F1 (lower brightness)
or if you have a Touch Bar, when hittingFn
,F1
should appear on the touch Bar.
A command line should appear at the top of the screen, type path
then select the line Shell Command: Install 'code' command in PATH
:
You will get a confirmation message that the VS Code path has been added. You can now open a new terminal and open VS Code from it using :
$ code pathfile/namefile.js
VS Code will open the file directly and you will be able to modify it without any hassle ! This can be particularly useful when modifying system files (MacOS, Linux or Windows) as VS Code will handle for you the request for access for modifying it (Overwrite with admin privilege).