2017-04-15 131 views
9

我們可以在VS Code中添加多個不同的終端嗎?我刨添加以下三個終端工作與所有那些如何在VS代碼中添加多個終端?

  1. Windows命令的提示
  2. 電源外殼
  3. GET慶典

我知道我需要添加以下在Preferences => Setting

// // 64-bit cmd if available, otherwise 32-bit 
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe", 
// // 64-bit PowerShell if available, otherwise 32-bit 
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe", 
// // Git Bash 
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", 
命令

我要添加的所有上述三個命令的setting.jsonenter image description here ,當我點擊+不同的終端應該打開,我想在不改變的喜好與終端工作。 VS編碼可能嗎?也許

+1

如果你輸入這個到powershell終端,它將啓動git bash:'&「c:\ Program Files \ git \ bin \ bash.exe」' – Davos

回答

12

有一種方法,使這種情況發生這些措施,通過安裝擴展:

  1. 找到一個擴展名爲Shell launcher並安裝它。重新加載VS代碼,如果你想要或完成所有步驟後。

  2. 轉到Files --> Preferences --> Settings,這將打開settings.json文件,然後插入這個(您可以編輯給你的心臟的內容):

代碼:

"shellLauncher.shells.windows": [ 
    { 
     "shell": "C:\\Windows\\sysnative\\cmd.exe", 
     "label": "cmd" 
    }, 
    { 
     "shell": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe", 
     "label": "PowerShell" 
    }, 
    { 
     "shell": "C:\\Program Files\\Git\\bin\\bash.exe", 
     "label": "Git bash" 
    }, 
    { 
     "shell": "C:\\Windows\\sysnative\\bash.exe", 
     "label": "WSL Bash" 
    } 
] 

PS:可以使用shellLauncher.shells.linuxLinuxshellLauncher.shells.osxmacOS

  1. 轉到Files --> Preferences --> Keyboard Shortcuts,然後在文件頂部找到打開keybindings.json文件。插入此:

代碼:

[ 
    { "key": "ctrl+alt+`", "command": "shellLauncher.launch" } 
] 

PS:你可以使用任何的組合鍵,但在這裏我選擇了按Ctrl + Alt +(反引號)`自己。

您可以重新載入你的VS代碼,然後點擊已分配的組合鍵,這將讓你選擇的選項,整合要使用終端。

enter image description here

有關詳細信息,請查看官方網站:https://marketplace.visualstudio.com/items?itemName=Tyriar.shell-launcher

享受!

+0

這不起作用。我想添加多個'terminal.integrated.shell.windows'而不是'Shell launcher' –

+1

我不認爲現在可以完成這項工作,但也許在未來,Ben會指出。這只是爲了讓多個終端通過安裝擴展進行一些調整,以便可以同時打開cmd,powershell或bash。 – ian0411

+0

非常感謝。 :) –

1

這可以通過在最後添加不同的鍵來完成。只需更改您的例子:

// // 64-bit cmd if available, otherwise 32-bit 
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe", 
// // 64-bit PowerShell if available, otherwise 32-bit 
"terminal.integrated.shell.windows2": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe", 
// // Git Bash 
"terminal.integrated.shell.windows3": "C:\\Program Files\\Git\\bin\\bash.exe", 

注意的關鍵...... shell.windows改爲... shell.windows2... shell.windows3

後續發現:我注意到,一旦重新啓動IDE,只有第一個終端顯示。我不得不重新打開設置並保存一次以再次獲得兩個終端。如果有更好的解決方案可以發佈

+1

我將這些設置添加到UserSetting,但第二和第三個彈出警告,警告消息是「未知配置設置」 –

2

ctrl + shift + `快捷方式,或按十字標記運行新終端,如果默認模式爲powershell,則輸入bash,如果默認模式爲bash,則輸入powershell。在這裏,你的終端被切換。

+0

這確實很好,但它不會在VSCode會話之間轉移,因爲它沒有對設置進行任何更改。 我個人喜歡這個,因爲它只是幾個關鍵筆劃,我並不總是需要多種終端類型。 – torpy

+0

這是迄今爲止最好的解決方案 – Pakk