Changing the default path of Visual Studio Code's integrated terminal

后端 未结 6 470
不知归路
不知归路 2020-12-24 13:07

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,

相关标签:
6条回答
  • 2020-12-24 13:45

    You can also set it to a relative path to the open folder with

    "terminal.integrated.cwd": "./example"
    

    So if you do menu FileOpen 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).

    0 讨论(0)
  • 2020-12-24 13:55

    Try this option in the "Intergrated Terminal" section of Settings.

    "terminal.integrated.cwd": "", 
    
    0 讨论(0)
  • 2020-12-24 14:00

    Thanks for the original answer from Peter. Definitely helped ! It has now slightly changed in more recent versions of VS Code.

    1. Navigate to File -> Preferences -> Settings
    2. Type cwd in search
    3. Choose Terminal > Integrated: Cwd settings
    4. Type the default path you want to set in the text block below (simply, no need for double hashes to escape)
    5. No need for saving, It's automatic
    6. Restart VS Code

    terminal cwd screen

    0 讨论(0)
  • 2020-12-24 14:08

    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"
    
    0 讨论(0)
  • 2020-12-24 14:09

    The below option will help you do this.

    Menu FilePreferencesSettings.

    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.

    0 讨论(0)
  • 2020-12-24 14:10

    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 FilePreferencesSettings


    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.

    0 讨论(0)
提交回复
热议问题