Open a folder in Sublime Text 3 using command line - command-line

I'm trying to open a directory in sublime Text 3.
I can launch sublime from the command line using the subl command.
The help text show the following:
Sublime Text build 3059
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin
Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
location.
Thus to open a directory I should be able to use the following
subl ./folder_name
but that does not work for me. Sublime does open (with a empty new document) and I cannot see the folder in the side bar.
Am I doing it wrong...
BTW. I'm using the fish shell with the 'Oh my fish' Add-on (I have also added the sublime add- on)...

Mac Or Linux Only
The best & safest way to do this is to create a symbolic link from the Sublime executable file (subl) to a folder already in your $PATH (e.g. /usr/local/bin/). If you do this; you won't have to update this every time sublime updates...
For users running BASH (i.e. most people):
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' /usr/local/bin/subl
If that doesn't work, create a bin folder in your home directory (if one does not already exist), add it to your PATH variable and create a soft link to that file).
mkdir $HOME/bin
export PATH=$HOME/bin:$PATH
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' $HOME/bin/subl
Then before you start using it properly, I would suggest taking a look at the help text first, which explains it's usage:
subl -h
e.g.
subl my_folder_name/filename.txt
subl my_folder_name
to open a file and folder in Sublime respectively.
Taking it a step further
I use a BASH function to take this a step further with the following benefits:
shorten the shortcut to just s (which is somewhat shorter than subl).
automatically open the current directory that you are if no file/directory is specified after subl / s.
If you want, you can use this function by running the following (after running the above):
cd
subl .bashrc
This should open the .bashrc file in Sublime Text. Add the following to the bottom.
function s {
if [ "$1" != "" ]; then
subl $1
else
subl $PWD
fi
}
Then you can open Sublime by simply typing in a s (all the sublime arguments still work)...
(Side Point, I also use a similar function for open (for mac) / or xdg-open (for ubuntu); where I shorten the command to just o. I use it a lot to open the current directory in the file manager)...
Fish Shell Users (you know who you are)
The export line above will not work; so exchange it for the following
set PATH $HOME/bin:$PATH
Before Edit
I had different versions of the command line subl and sublime text three installed. I simply removed the subl command and then re-added and that fixed the problem for me...
For those who may find this useful - this is what I did:
subl -v
This showed me the build of the command-line sublime, when I checked this against the version of my actual Sublime, I noticed that the command line subl was an older build. So I tried to find the location of the command line subl using the following command (for me this was /usr/bin/subl):
which subl
So I first removed this older command-line sublime text.
sudo rm /usr/bin/subl (use `sudo` only if necessary)
And then re-added Subl to my PATH (as above)

To open sublime in the same folder you can simply type in your commandline:
subl .
In order to work you must configure some stuff:
1) To prevent the opening of previous projects you should set the following properties of your Sublime User Settings:
"hot_exit": false,
"remember_open_files": false
2) In order to use subl.exe from anywhere you should add the Sublime folder in the environment variables. I.e.
C:\Program Files\Sublime Text 3

That's because by default the side bar does not show, you can show the side bar by
View > Side Bar> Show Side Bar
[1

I've had this issue before, on both Mac OSX and Windows, and I found some oddities with it;
Mac OSX
You either have to have Sublime Text open already for the subl ./folder_name command to actually open the folder, or Sublime must have been quit with windows still open - if you close all the windows then quit Sublime, using the subl ./folder_name command will just open a blank Sublime window.
Windows
You have to have Sublime open for the subl ./folder_name to work. Without Sublime open, it will just open a blank Sublime window.
I've yet to find a way of the command opening fine, no matter how you quit Sublime / when you have Sublime closed.
Try having Sublime open whilst you run the command, and see if it works then.

To open a folder as a project in Sublime Text, use subl . while in the folder you're trying to open.
Linux
So if you want to open ~/Documents/folder_name, then move to that folder in Terminal cd Documents/folder_name and type the command subl .
Note This was only tested in Ubuntu with Sublime Text 2.
Edit Answer found here: http://olivierlacan.com/posts/launch-sublime-text-3-from-the-command-line/

I was having trouble opening sublime text 3 with sublime text 2 currently installed. To fix this issue:
1) open /usr/local/bin from terminal.
2) locate and delete subl within bin folder
3) copy and pasted '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' /usr/local/bin/subl into terminal.
4) locate new subl within bin folder
5) used subl in terminal to verify command opens sublime text 3 properly.
6) used subl -v and got Sublime Text Build 3083

MAC OSX Open terminal and run following command:
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'
/usr/local/bin/subl
The above command is needed only for first time. After this configuration, whenever you go to folder where your project is present, run following command:
subl .

While there are already multiple answers and I apologize for adding to the noise, I don't understand why you're using subl ./folder_name to open a local directory. Why not use subl folder_name/ instead?
Either way my ST3 (build 3083) installation on OS X is opening a child directory with either subl ./child or subl child/ whether Sublime was open prior to the command or not.
PS: Make sure you don't have the sidebar closed when opening directories by running Command + K then B. I've often assumed a directory was failing to open just because I had my sidebar closed and couldn't see the files listed inside of it.

There is probably an alias with the name subl provided by 'Oh my fish' . You can check if there is an alias by using alias command in the terminal. This will display all aliases for your session. If you have it on the list then it is colliding with your symbolic link. Disable the alias by fixing the source or by using unalias subl (unalias will only fix it for the current session)
I had this problem when using bash-it aliases for osx. Disabling it fixed the problem for me.

For Linux and MacOs users and Sublime Text 3
Try the command :
subl3

Related

MacOS gives zsh: command not found: flutter after updating path according to Flutter Official Docs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
Recently I updated Mac OS to latest Catalina and my terminal which is using zsh now start showing me following error:
zsh: command not found: flutter
It was working fine before update.
You need to update the environment path.
Open terminal.
vim $HOME/.zshrc
Press "I" key for going to insert mode.
add the following line in the opened file:
export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"
Press "Esc" then write :wq! in terminal and press enter to exit vim.
Reopen the terminal and check "flutter doctor"
If this solution did not work, remove the double quote from path or use the full path explicitly instead of ~.
Working on macOS Catalina 10.15.5 (19F101).
I have used .zprofile instead of .zhrc
Provide Full Disk Access to Terminal by
Setting -> Security & Privacy -> Full Disk Access. Add Terminal
If the current terminal uses bash, change to zshell using the below command
chsh -s /bin/zsh
In the root directory i.e something like /Users/^YourAccount^ execute the below
touch .zprofile
vim .zprofile
Press I to enter insert mode. Type the below
export PATH=$PATH:/Users/^YourAccount^/^YourPath^/flutter/bin
Save and quit by pressing Esc, then :wq and Enter
Close Terminal and reopen Again. Then try executing flutter command
For me removing double quotes did the fix.
Try changing
export PATH="$PATH:[PATH TO FLUTTER]/flutter/bin"
into
export PATH=$PATH:[PATH TO FLUTTER]/flutter/bin
adding few more steps for easiness:
Open terminal.
vim $HOME/.zshrc
Press "I" to open insert mode.
add the following line in the opened file:
export PATH=$PATH:[PATH TO FLUTTER]/flutter/bin (remember I don't have double quotes here)
Press "Esc" then type :wq in terminal to exit edit mode.
Type
source .zshrc to reload the terminal for changes
You must update your environment $PATH variable.
1) Open the file $HOME/.zshrc $HOME is your home path
2) add the following line in the opened file:
export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"
3) save the changes and restart your terminal session.
The process is also documented here
Follow these steps:
Open finder
Enter Cmd + Shift + G
Type ~ in Go to the folder popup.
Now enter Cmd + Shift + . to show hidden files.
Open .zshrc
Add this line
export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"
Replace this /YOUR_FLUTTER_DIR with the path to your flutter directory.
In my mac, the path is
export PATH=$PATH:$HOME/FlutterDevelopment/flutter/bin
in android studio terminal, simply just type this command:
export PATH="/YOUR_FLUTTER_DIR/flutter/bin:$PATH"
change YOUR_FLUTTER_DIR to your actual directory
I updated from Mojave to Catalina and running Terminal, switched to the default/preferred zsh shell, from the bash shell.
Then was hit with
zsh: command not found: flutter
so, followed the advice seen elsewhere to only add the following to Users/MyUserId/.zshrc
export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"
echo $PATH showed that /Users/MyUserId/flutter/bin was now one of the configured PATHs.
However, I couldn't get "flutter doctor" to work but came across a post on jelliesgame.com which suggested copying
Users/MyUserId/.bash_profile to Users/MyUserId/.zshenv
Now, flutter doctor gives a clean bill of health
This worked for me:
Steps:
Type on the terminal:
open .zshrc (This opens the document in text edit)
Add this to the end of the file:
export PATH="/Users/YOUR_USERNAME/Documents/code/tools/flutter/bin:$PATH"
Save and close .zshrc
Then type:
flutter doctor
Had the same issue and just realized that I forgot to add the close quote
So the correct way is to add to .zshrc by typing vim ~/.zshrc
PATH="$PATH:$HOME/Flutter/flutter/bin"
or
export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"
then run source ~/.zshrc or just open a new terminal window
I tried installing flutter on my MAC according to the advice here, but it still doesn't work, after searching for it I found an article here.
So, I change my .zshrc file to:
export PATH="$PATH:/Users/YOUR_PROVILE_NAME/YOUR_DEVELOPMENT_FOLDER/flutter/bin"
Change YOUR_PROVILE_NAME to your name profile, also YOUR_DEVELOPMENT_FOLDER to your development folder for flutter
and now it's working.
Note:
I use Catalina OS v10.15.4
I followed URL to resolve my issue.
I simply created a .zshrc file which was not exist then added my PATH variables copied from existing .bashrc.
I had the same problem when upgrading to mac Catalina 10.15.4:
After many days of research, I have achieved success. Here are the steps I did:
First, open the terminal on your mac.
Next, use the command
cat .bash_profile
and copy the content.
Then type this command into the terminal:
nano $ HOME / .zshrc
and paste the content just copied above into. Save then type
source $ HOME / .zshrc
to refresh this file. Next type
echo $ PATH
to see if the content has been updated. If successful type
flutter --version
and you will see the result.
There are quite a few answers mentioned above pretty much same. I would say worth seeing into the SHELL using echo $SHELL command,
If you’re using Bash, edit $HOME/.bash_profile or $HOME/.bashrc. If you’re using Z shell, edit $HOME/.zshrc. If you’re using a different shell, the file path and filename will be different on your machine.
N.B. Don't forget you need to add VIM before either command in the terminal app.
For further details, click the link Update your path, and look into the section Update your Path. I hope it would help many especially new comers to MAC OS. Cheers
For me .zshrc worked instead of .zprofile. I believe this is because I had created .zshrc earlier and now when I tried creating .zprofile, it was looking into .zshrc file.
You can check if .zshrc file using ls -a command

How to open folders in VSCode via Terminal in a fresh state?

It appears that VSCode always opens a folder in with the last UI state it had.
I'm looking for something like Sublime's remember_open_files: false, or in other words, I would like VSCode to open up with a clean UI state regardless of what state the UI was in the last time the folder was open.
What's happening now:
cd my-project-folder/
code .
# VSCode opens folder with saved UI state
What I want:
cd my-project-folder/
code .
# VSCode opens folder with fresh UI state
I tried to do it through command line using the command
code -n .
which should have opened VS code in current folder with a new session but it does not seem to work at all. I believe that code . seems to ignore the -n new session option and restores the previous session for the folder. So this feature is probably not implemented in VS code.
(Refer here for the commandline options for VS code.)
this is the command that works for me on windows
code -r .
From inside VS Code built-in terminal, cd into your project folder/directory and enter command:
code -a .
Note period at end.
This will open your current directory/project folder without opening a new window.
Part of the answer on this thread worked for me. Basically, make sure VSC is in the Applications folder. Then open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart Visual Studio Code if it's open. In terminal, navigate to the folder you want to open in VSC, and type code .. Hopefully it should work for you.
If you are using a Mac, you need to first install the VSCode command amongst the shell command list.
Do this:
Open VSCode
press CMD + SHIFT + P
type shell command
select Install code command in path
navigate to any project from the terminal and type code .
code . opens VS Code at the current terminal folder
If you are using VS Code [Version: 1.50.0] then open your command prompt and go to your project's directory and just run the command:
code -a .
i.e. [Also can see the photo]
[1]: https://i.stack.imgur.com/sMmkH.png
$ code . --user-data-dir=.
This will open Visual Studio Code in current working directory. I use Bash with Ubuntu 16.04LTS.
I am using VS Code Version 1.24.1 (As of the time of original posting).
If you want to open a folder through the terminal, you can execute the command:
code -n name_of_your_folder/
or
code -n path_to your_folder/
Same thing goes for a file, and these open VS Code in a new window.
Also, note that you should have VS Code installed.
You're welcome!
I checked through all of the settings available in the VSCode preferences for me, and I don't think there is a way to do this.
There are some settings related to what VSCode window instance that folders will open into, but nothing that seems similar to Sublime Text's remember_open_files setting.
The closest thing I found was running code --user-data-dir . (feel free to replace . with some other directory so you don't pollute your current working directory) from the terminal to specify that VSCode shouldn't remember ANY previous settings, but this seems like overkill for what you're trying to accomplish (as VSCode will literally run as if it's the first time it's being run after a fresh install).
EDIT: I just discovered a View: Close All Editors command in the command palette (CMD + SHIFT + P). The keyboard shortcut for OSX is CMD + K, CMD + W, and this will close all the files you have opened!
I have the same problem on Mac.
I solved it in the following steps:
I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
Type "shell"
Click on 'Install code command in path'
Give an administrator password
You will get a message that it has been installed
Now run "code ."
NB: Make sure you already cd into the folder you want to open before you run code .
If you want to open folder with vscode, you just go to folder ( you can user terminal or file explorer) with terminal, and do "code ."
To get the right folder in VS Code v 1.50.1 Terminal I tried a lot of options which didn't work for me. At the end I found very easy solution. I went to File->Open Workspace and found that my Workspace had the wrong folders inside it, which I simply deleted (from Workspace only!). Then I opened the folder I needed in my Workspace, opened Terminal->New Terminal, and everything worked perfectly well. Please let me know if this will work for someone else.
This command works to open a specific folder in VS code using terminal
code -r Documents/VS/C++/
here -r switch is used to open a file or a folder in an already opened VS code window
and then you specify the path of the file or folder you want to open
if you want to open it in a new window use -n switch instead of -r
This works for me with VSCode on Linux:
cd path/to/project
codium .
I tried every mentioned answers, what's work from me is this:-
I created a shell script to open folders.
$ sudo nano /usr/local/sbin/code2
/usr/bin/code-oss -n --user-data-dir '/home/myusername/.config/Code - OSS2/' -a $#
$ sudo chmod +x /usr/local/sbin/code2
You can remove --user-data-dir '/home/myusername/.config/Code - OSS2/' from the script if you want to use default code-oss config folder.
When I want to open a folder, I use the command like this :-
$ code2 .
I add this command code2 to open with option thunar to open folders directly from files manger.
Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd
the type code . and that will open the folder and the files in it inside vs code. works like a charm.
If Visual Studio Code is installed using flatpak then a bash alias can help launch the application from the terminal.
alias code="flatpak run com.visualstudio.code"
I did it a simpler way just by three steps. I am currently in a project folder and want to open another folder in vs code using the cli or terminal. What I first did is navigated in the folder which I wanna open in vs code inside the terminal. Once I m inside that particular directory or folder I simply typed the command :
start code .
This will open that directory or folder in a new vs code window.
The complete process is :
open the terminal is vs code
navigate to the folder u want to open
once u r inside that particular folder type the command :
start code .

How to open a file from the integrated terminal in Visual Studio Code?

Is there a way of opening a file from the terminal in Visual Studio Code that opens in the same vscode instance that runs the terminal? Similar to c9 tool in Cloud9.
I'm aware of the code tool, but when you run code something.php from the integrated terminal it opens a new vscode instance, which is not what I want...
You can use -r or --reuse-window command line option.
code -r something.php
just
code file_name
I tried it on Win10 and on Linux (Ubuntu)
I don't know what operating system you're using, but on MacOS you can just say open filename.ext in the integrated terminal, and it will open a new tab in the same VSCode instance, ready for you to edit.
If you are having command not found: code in macOS, use a full path to it.
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]
Open Visual Studio Code
Press CMD + SHIFT + P (this opens "Command Palette")
Type shell command
Select “Install code command in path”
Navigate to any project from the terminal, and type code .
If it didn't work, select “Uninstall code command from path” first, then reinstall it again.
I use code -r . to open the current directory in the main window.
You can use the code command from the CLI to open a file, but if you want it to open in the existing window, either use code -r <file> as mentioned in other answers (which does work for me on Ubuntu Linux), or, if -r does not work (under WSL?), make sure window.openFilesInNewWindow is either off or default in settings.json or the in VS Code settings UI, then use code <file>.
Many things can be found in open --help
A work around that worked for me on MacOS is:
open -a 'Visual Studio Code.app' something.php
in the version 1.31.0 that I have installed, on Windows 7, the only way I found to do this is to e.g. change the file associations in system so that .cproj and .cs files are opened by Visual Studio Code by default, and type "filename.cs" in Terminal to open file by that name in the same window... -r option is not working for the first call (opens a new window), but with each subsequent call that same window is correctly reused. ok can't get to open whole directories this way - it's a bit shoddy anyway. probably it would be more convenient to use an outside shell and work with "-r" option
VSCode 1.64 (Jan. 2022) comes with a new command:
Keyboard Navigable Links
Previously, link navigation in the terminal required the use of a mouse.
Now, links can be opened using only the keyboard via the following commands:
Terminal: Open Detected Link... to view all links (web, file, word)
Terminal: Open Last Web Link... ex: https://github.com/microsoft/vscode
Terminal: Open Last File Link... ex: /Users/user/repo/file.txt
Check if the last command Terminal: Open Last File Link... would help in your case.
See also "Terminal shell integration"

How to open file using vscode terminal?

I want to open a new tab and open a file using vscode terminal.
like open somefile.js command, so I can use ls and open file quickly.
Use code -r <file> to open the file in the last active code window
use
code -r <filename>
just remeber to install the code command to PATH. in VScode, open the command palette and type "code", you should see a Shell Command: Install code to PATH option.
I really haven't actually seen any difference between using the command without the -r flag.
If you are already in VSCode terminal (not an external OS terminal), check out the latest VSCode 1.64 (Jan. 2022) Terminal shell integration:
The terminal now features experimental opt-in shell integration which allows VS Code to gain insights on what is going on within the terminal as it was previously a black box.
When enabled using "terminal.integrated.enableShellIntegration": true, arguments to run a shell integration script will be injected into your terminal profile if possible.
The script itself mostly just injects invisible sequences into your prompt, providing us with information like where the prompt, command and command output is, what the current working directory (cwd) is for each command and the exit code of each command.
That means:
Link support relative to the cwd
Since we know the cwd for each line in the terminal buffer, we can support opening links in the terminal relative to the cwd at the location where it was activated.
Before, when a link was clicked, a quick pick would open with results from any folders containing a match for that name.
Now, the exact file match will be opened.
In a terminal with a cwd of VSCode, package.json is echoed.
Clicking on the file name will result in vscode/package.json opening.
The directory is changed to be the template-string-converter and then package.json is echoed.
Clicking on the file name will open template-string-converter/package.json.

How to call VS Code Editor from terminal / command line

The question says it all.
How can I open VS Code editor from
windows cmd
linux and mac terminal
e.g. for notepad++ I write
> start notepad++ test.txt
By the way, the editor is awesome (cross-platform)! Thank you Nadella!
You can download it from microsoft
To open a file or directory use the command:
code /path/to/file/or/directory/you/want/to/open
For macOS users, it needs to be installed manually:
Launch VS Code.
Command + Shift + P to open the Command Palette.
Type shell command, to find the Shell Command: Install 'code' command in PATH and select to install it.
Restart your terminal.
Per the docs:
Mac OS X
Download Visual Studio Code for Mac OS X.
Double-click on VSCode-osx.zip to expand the contents.
Drag Visual Studio Code.app to the Applications folder, making it available in the Launchpad.
Add VS Code to your Dock by right-clicking on the icon and choosing Options, Keep in Dock.
Tip: If you want to run VS Code from the terminal, append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Now, you can simply type code . in any folder to start editing files
in that folder.
Tip: You can also add it to VS Code Insiders build by changing "com.microsoft.VSCodeInsiders". Also if you don't to type the whole word code, just change it to c.
Linux
Download Visual Studio Code for Linux.
Make a new folder and extract VSCode-linux-x64.zip inside that folder.
Double click on Code to run Visual Studio Code.
Tip: If you want to run VS Code from the terminal, create the following link substituting /path/to/vscode/Code with the absolute
path to the Code executable
sudo ln -s /path/to/vscode/Code /usr/local/bin/code
Now, you can simply type code . in any folder to start editing files
in that folder.
VS Code is a must have code editor for 2018
For Windows 10 users a lot is possible, the same way the Mac OS users type code . .
Look for you VS Code \bin folder path e.g C:\Program Files\Microsoft VS Code\bin . The bin folder includes a file called code.cmd .
If you are not sure about what is your path, type where code.cmd, and then, copy it without the \code.cmd after the ...\bin.
Follow the steps below and be proud of the OS you use.
Search for "Advanced System Setting" from Start.
Click on Environment Variables.
On System Variables choose "path" from Variable tab and click on Edit.
Click on New on the right side of the popup window.
Copy your path from the Explorer's breadcrumb path and paste it into the new opened path in step 4, example:- C:\Program Files\Microsoft VS Code\bin.
Click Ok on all the open windows to confirm changes and restart your cmd .
Go to your cmd and navigate to you working directory on server and type code . .
C:>cd wamp64\www\react-app> code . to open with VS Code on Windows.
Visual Studio Code also includes a command prompt (terminal) window and you can open one or more of them with:
Ctrl + ` on your keyboard.
Hope this helps some one like it did to many of us.
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 (⇧⌘P) and type shell command to find the Shell Command: Install code command in PATH command.
Mac shell commands
Restart the terminal for the new $PATH value to take effect. You'll be able to type code . in any folder to start editing files in that folder.
For VS Code Insiders Windows users (vs code doc):
Add the directory "C:\Program Files (x86)\Microsoft VS Code Insiders\bin"
at %PATH% environmental variable.
then go to the folder that you want to open with vs code and type:
code-insders .
Sometimes setting path from VS Code command palette does not work
Instead manually add your VS Code to your path:
Run in terminal
sudo nano /etc/paths
Go to the bottom of the file, and enter the path you wish to add
Hit control-x to quit. Enter “Y” to save the modified buffer.
Restart your terminal and to test echo $PATH. You should something similar
~ echo $PATH /Users/shashank/.nvm/versions/node/v8.9.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
Next time, you navigate to your project folder from terminal
Enter:
code .
or
code /path/to/project
Source
In the case of Linux and Mac, you want to navigate to the directory that you extracted the VSCode files using the 'cd' command. For example:
cd ~/Downloads/VSCode
Then you start the application by running..
./Code
'Code' being the name of the executable.
If you have root access on the machine, you can configure the system to allow you to start VSCode from anywhere by linking it to /usr/bin, where links to executables are often stored.
sudo ln -s /path/to/VSCode/folder/Code /usr/bin/Code
You can now launch VSCode from anywhere by typing:
Code
For command line heads you can also run
sudo ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code
this will do the exact same thing as the Shell Command: Install 'code' command in PATH command feature in VSCode.
When installing on Windows, you will be prompted to add VS Code to your PATH.
I was trying to figure out how to open files with VS Code from the command line and I already had the capability - I just forgot I had already added it. You might already have it installed - check by navigating to a folder you want to open and running the command code . to open that folder.
In linux if you use code . it will open VS Code in the folder the terminal was in.
Using code . Filename.cs it will open in folder and open said file.
For linux Debian the below can be done
$ export PATH=$PATH:/usr/share/code
Then run it
$ code
$ code file.py
$ code workingdir
Open command line and type:
cd your_folder_path
code.cmd .
or
code.cmd your_folder_path
It will open your folder in Visual Studio Code.
Make Sure, you are inside the correct folder after executing "cd your_folder_path" command.
On Windows you can add the following path to the system environment variables.
C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin
This works for Windows:
CMD> start vscode://file/o:/git/libzmq/builds/msvc/vs2017/libzmq.sln
But if the filepath has spaces, normally one would add double quotes around it, like this:
CMD> start "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln"
But this messes up with start, which can take a double-quoted title, so it will create a window with this name as the title and not open the project.
CMD> start "title" "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln"
typing "code" in dos command prompt worked for me
On Ubuntu the flatpak version seemed broken. I uninstalled it and downloaded the deb package right from Microsoft.
I use the following command to load a project quickly (in linux)
cd into the project cd /project
run command code pwd
similar steps can be used in other Os too.
In linux terminal you can just type:
$ code run
Windows:
Add code CLI path in a system environment variable.
in windows default code cli path is (username is you pc username)C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin
Then you can check it like this by taking your project folder and open new cmd and type code .
Step 1: create a .bat file with the name you want e.g vscode.bat
Step 2: Write your path to Visual Studio Code
Step 3: Save it in C:\Windows\System32 directory
**
C:
cd Users\Bino\AppData\Local\Programs\Microsoft VS Code
Code.exe**
Step 4: You can call visual studio code from any where by typing "vscode" which is the name of your bat file
This will work. This is your directory name "Directory_Name"
sudo code --user-data-dir="Directory_Name"
Other easyway to do it on mac is :go to Command Palette[ Shift ⇧+ Command (⌘)+P] and type :Shell Command: Install 'code' command in PATH
once installed: Shell command 'code' successfully installed in PATH.
Then you can use code from the terminal as well.
If you install VS CODE using snap. You will need to add /snap/bin in your PATH environment variable.
so - open your .bashrc or .zshrc
and add :/snap/bin in your PATH environment variable
reload terminal,
and than code comand will start it
A simple way is to go to your Project where you want to open it and type
code.cmd D:\PathTo\yourProject\MyProject
That's it. It will open your project in Visual Studio Code.
Delete old virtual environment and create a fresh virtual environment.
In a way I am reticent to add to the long list of answers. However, I searched this page for the word "portable" and came up empty. (And I did a full Stack Overflow search and also found nothing.) So I want to add this very specific answer for potential future searchers.
This answer is for if you installed VS Code in Portable Mode on Windows 10.
"Portable Mode" refers to what is described on the official VS Code web pages, which as of 21 January 2021 are found here: https://code.visualstudio.com. It does not mean the Visual Studio Code Portable project started/run by Gareth Flowers, or any similar project. (I am not saying anything bad about this or other projects - I have neither used nor evaluated.) If you are using one of those projects, you need to check with that project documentation/community - although this might work.
"Installing" VS Code in Portable Mode is downloading a .zip archive and extracting it locally wherever you want your VS Code "installation" to live. There is no actual installation or setup that is run, so there is no automatic adding of the code command to your PATH.
Answer
After extracting the Portable Mode VS Code files to the location of your choice, there should be a bin folder in that location. Copy the full path of that bin folder and add it to your System or User (your choice) PATH variable.
You should then be able to use the code command from PowerShell or CMD.
In linux you need to check first what is the name you your vscode binary file
When you get the binary file name check where it is by using this command :
whereis your_file_name
Go to the / (root) and go to bin and rename file with any name what you want to call it.
To rename : mv your_file_name your_changed_name
Now you can access vscode from any where in terminal
This works on Debian based Os definitely