I'm trying to change the default path of the integrated terminal in Visual Studio Code, but I'm not sure how to. I do know how to change it in the windows command prompt, but not in Visual Studio Code. I looked in user settings, but I can't find anything there to change.
The current default path is C:\Users\User_Name.
I'd like to change it to C:\Project.
How do I do this in Visual Studio Code?
Short answer
Edit the user preference "terminal.integrated.cwd": "" to the path that you want the integrated terminal to open to.
Long answer
The same answer, but the long step-by-step version,
In Visual Studio Code go to:
Menu File → Preferences → Settings
Now that you are in the "User Settings", using the "Search Settings" bar across the top of the window paste or type this:
terminal.integrated.cwd
It will list the following as a result:
// An explicit start path where the terminal will be launched, this is used
as the current working directory (cwd) for the shell process. This may be
particularly useful in workspace settings if the root directory is not a
convenient cwd.
"terminal.integrated.cwd": "",
You will notice that it will not let you type here to change this setting. That is because you can't change the default setting. You instead need to change your personal settings. Here's how...
Click the pencil icon to the left of the this option and then the "Copy to Settings" option that pops-up.
You should have a split screen in which the right side of the screen has the heading Place your settings here to overwrite the Default Settings. This is the correct place for you to make changes. You might already have a few personalized settings listed here.
When you clicked "Copy to Settings" it automatically added this line for you:
"terminal.integrated.cwd": ""
Notice that whichever item is last in this list will not have a trailing comma but any items before it in the list will require one.
FYI: you could have simply typed or copy/pasted this into the personalized settings yourself, but following these steps is the process to learn for changing other preferences as needed.
Now you are able to type to set the path you want to use. Make sure to use \\ in place of \ and you do not need the trailing \. For example including this line would always start your terminal in the baz directory:
{
"terminal.integrated.cwd": "C:\\Users\\foo\\bar\\baz"
}
To apply the change, simply Save and restart Visual Studio Code.
As others have already explained, you can add a setting to change the default folder for your integrated terminal to start in. This setting also accepts Visual Studio Code variables, so to make a relative path from the root folder of your workspace you can use ${workspaceFolder}.
For example, for your terminal to always start in the subfolder mystart, your setting would be:
"terminal.integrated.cwd": "${workspaceFolder}/mystart"
Thanks for the original answer from Peter. Definitely helped !
It has now slightly changed in more recent versions of VS Code.
Navigate to File -> Preferences -> Settings
Type cwd in search
Choose Terminal > Integrated: Cwd settings
Type the default path you want to set in the text block below (simply, no need for double hashes to escape)
No need for saving, It's automatic
Restart VS Code
terminal cwd screen
Try this option in the "Intergrated Terminal" section of Settings.
"terminal.integrated.cwd": "",
You can also set it to a relative path to the open folder with
"terminal.integrated.cwd": "./example"
So if you do menu File → Open Folder... → project, and open the terminal with your keyboard shortcut, it will open to ~/project/example automatically.
It can be a general folder like src you would always use, or a specific one (but then it would be best to save it in file .vscode/settings.json).
The below option will help you do this.
Menu File → Preferences → Settings.
Add or edit the below setting.
terminal.integrated.shell.windows": ""
From the next terminal it will be reflected.
And add file .profile to your default shell, and add the default path to it.
More information can be found
at Integrated Terminal.
Related
i want to integrate git bash console inside vscode and i've seen several tutoriales but all of them point that i have to go to preferences and settings, and settings should open settings.json but i get a user interface instead and i can't find a way to get the entire file, instead i get like isolated settings.json files for every element on that interface.
You can find the settings.json by:
Bringing up the command palette with the keys Ctrl+Shift+P.
Then typing and selecting >Preferences: Open Settings (JSON)
It's important that you do not choose Preferences: Open User Settings as this will open the GUI.
I have highlighted the option that you need choose.
To open settings.json, press ctrl+shift+p and then search for open settings. You'll see two options for json file. Choose the one you need.
I edited the settings file and there must have been a typo and now the app crashes on startup.
Online the documentation says the settings lives in $env:LocalAppData\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
I can't figure out what that path means since it doesn't exist on the computer.
I re-installed the app to fix the problem then made sure to see what the actual path is.
It's located in : C:\Users\{USERNAME}\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
In the current version (1.7.1033.0), the application can open the JSON settings file for you via a button. Open the Settings tab, and the bottom left corner will have a button named "Open JSON file". Clicking that button will open a prompt asking with what application to open the file. That text editor can then tell you where the file is located.
If you open the terminal settings, it will open a text editor with the settings.json file. If your default editor is VS Code it will show you the path below the tabs on the top of the screen.
I'm unsure what other editors show you the path, but if it is crucial you can change your default text editor to Code.
There is still the option to open the JSON file through settings. In version 1.15.2875.0 you can still find the "Open JSON file" at the bottom left corner
Screenshot with highlights
This hint was given by a comment by user1340531:
Mine is at C:\Users\{username}\AppData\Local\Microsoft\Windows Terminal\settings.json
(or more generically: %userprofile%\AppData\Local\Microsoft\Windows Terminal\settings.json)
If it's not there, you should consider OP's answer or vyps comment which lets you find out one of these generic paths (they are equivalent):
%userprofile%\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
%LocalAppData%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
$env:LocalAppData\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
If you don't know what these paths mean, I'd recommend playing around with "Windows Run" (Win+R) and the explorer address bar.
If I open ~/foo.txt then open ~/baz/bar.txt from Terminal, Sublime Text always opens 2 different windows. It's aggravating to have all these different windows open..
I've tried changing a bunch of ST's settings, but nothing seems to fix this.
Is there a way to have ALL files and folders just open up in the same window as if I were manually adding all these folders to the project?
In Sublime Text Menu:
Preferences -> Settings - User
Look for 'open_files_in_new_window'
And change 'true' with 'false'
Rather than editing the SublimeText default settings (as Jahnux73 suggested), you should go to Preferences -> Settings - User, and add the following:
"open_files_in_new_window": false,
The SublimeText default settings file should not be modified, as it may be overwritten by Sublime updates, and so that you'll always be able to restore the default settings. The way Sublime works is that at runtime, it reads and applies the default settings, and then reads and applies the Settings - User file. In the event of a conflict, the User settings take precedence. That way, you can add your own settings without modifying the default configs.
Folder can be directly dragged to sidebar, or from menu bar select
Project --> Add Folder to Project.
And better, since this has the same functionality as File -> Open folder which isn't mapped to a shortcut by default. You can make this a key mapping by going to
File -> Preferences -> Key bindings and append
{ "keys": ["ctrl+shift+o"], "command": "prompt_add_folder" },
then you can use CTRL+SHIFT+O to add a folder.
Drag files or directories to sublime window will add them to current window instead of opening new one.
All the answers above indicate the parameter files only, but this does not work for folders.
I found this solution:
You need to go to the registry path HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3\command
Change command add the parameter -a, get: C:\Program Files\Sublime Text\sublime_text.exe "%1" -a
Also, if You have a custom alias for the console, you can use it like this: subl . -a
For mac OS two changes are needed
1-
Preferences -> Settings - User
Look for 'open_files_in_new_window'
And change 'true' with 'false'
2-
In system Preferences find the Dock and then change its setting for the option “Prefer tabs when opening documents” and choose Always.
Then do :
subl folder_1
subl folder_2
subl folder_3
I explained in details here
All those replies above didn't work. Here I found the real solution to this problem: -
Click Preferences
> Settings - Distraction Free
Then add these lines in user panel:
"open_files_in_new_window": false,
And click Save.
Here you go!!
None of the answers above worked for me.
I had a Sublime app icon pinned to the Dock and every time I opened a new file through the Finder context menu (Open With > Sublime Text.app) it went to a newly opened instance of Sublime that's displayed in "recent apps" zone of the Dock. So I always had 2 icons in the Dock, each with different set of tabs.
I simply removed the first icon from the Dock, and pinned the one from "recent apps" area, and dragged it to the place where the first icon used to be.
This seems to work fine provided that you set "open_files_in_new_window" to "false" (Preferences > Settings), as suggested in other answers.
To accomplish this I've been right-clicking the file or directory and then selecting Show in Windows Explorer, and then copying the path out of the address bar.
Is there an add-on or macro that can make this task easier?
I'm aware that you can drag a file from Solution Explorer into the editor and it will write out the path, but when doing web development I don't always want the server path, sometimes I want the local path.
Look at PowerCommands extension
http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99?SRC=Home
Among others, it contains "Copy Path" command for files and folders
UPD: Also, another option: right-click the tab of open document and there will be "Copy Full Path" command. It's built-in, no extensions needed
You can just select the file in the 'Solution Explorer' file list and hit CTRL+C. It automatically copies the file path to your clipboard.
I've found one more option of how to solve it without plugins (for VS 2015 and above; not certain about previous versions)
Go to "Tools" -> "Customize..." -> "Commands" tab.
Choose "Context menu:" and "Project and Solution Context Menus | Item" and you can add any existing Command.
In order to copy path, choose Category "File" and "Copy Full Path" command. Will add button only for files in Solution Explorer.
This works for projects as well but you should choose "Project and Solution Context Menus | Project" (copy path of .vcxproj file).
It doesn't work for solutions and I don't understand actually why.
Tools > Options > Environment > Keyboard
You can set your own shortcut keys for anything. The two that are most relevant to this post are "File.CopyFullPath" and "File.CopyRelativePath".
I created my shortcut to just be used in "Text Editor" and it has worked great.
This was asked for VS2010 and I'm using VS2019, so it is an old question, but still relevant. I knew about the file header right click menu, but for some reason I didn't think about the shortcut keys until I read this question. Posting in case this results in a quicker fix for anyone else.
The CTRL+C doesn't work for me on MSVS 2017.
Use the copy as path extension here.
Then right click on file in solution explorer -> Copy as path (or assign a shortcut).
I find that it works very well.
In Visual Studio with TFS as source control, when I view the history and double click a cs file, the file is loaded in notepad. How can i change the application to be notepad++?
I also would like the OS's default application for the file to still be visual studio
After pouring over ProcessMonitor logs I think I found the solution!
You need to change the what the Windows shell (explorer) thinks the "Edit" action for text files. I was able to change this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\text\shell\edit\command
to something other than Notepad (in my case notepad2). Now Visual Studio's TFS's changeset dialog opens cs files with that editor.
This will probably change the edit option for not just cs files, but everything considered "text'. The registry entries for file associations are pretty complicated. I suspect that it would be possible to disassociate .cs files from this common "text" category and make this change only for cs files (but I'm not that ambitious). Also, I wouldn't be surprised if people's file associations / shell commands (open, edit, etc...) vary from machine to machine (OS versions, tools installed, etc) - so YMMV.
The only way I found is to replace notepad with notepad++. This article describes how to do it. Don't forget to check the comments to get a link to the "little exe" that comes with notepad++.
Works like a charm on W7 x64.
Cheers,
Phil
\I was able to configure this by adding new value to the registry.
OS: Windows 7 Enterprise x64
Steps on how to do it.
Run: Regedit (alt + r, type regedit)
Look for HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations
Right click "SystemFileAssociation" -> add new key then name it as .cs
Right click .cs and add new key then name it as shell
Right click shell and add new keys name it as edit and open 6
Right click edit and add new key command then change the default value to point to the file exe you want it to run.
ex: C:\Program Files (x86)\Notepad++\notepad++.exe %1
Don't forget to add the %1 at the end of the .exe
do the same for open
Hope it helps.
I don't see any options in Visual Studio for changing that, so I'm guessing it uses the system's default text editor.
Try assigning Notepad++ as the default handler for *.cs files.
You can do this from withing Notepad++ by going to Settings/Preference/File Association.
You can also do it by right-clicking on a .cs file in explorer, go to Open With/Choose Program..., then select Notepad++ and check the "Always use the selected program to open this kind of file" box before hitting OK.
The only thing that works for me is when I set the default program for the particular file type in Windows Explorer to open with the VS IDE:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
This opens the code in a new instance of VS. Not ideal, but at least it's easier to read.