設置vscode終端cmd、powshell、cmder編碼爲utf-8
用vscode遇到的一些問題
用vscode寫c++程序時,debug調試和直接運行在終端顯示的編碼格式不一樣,導致亂碼,要經常改右下角的編碼格式,非常麻煩,接下來提供幾種方法
運行程序時終端cmd顯示的編碼設置爲utf-8
打開vscode,左上角文件-首選項-設置,搜索框中搜 setting.json
然後點在setting.json 中編輯
將這段加入配置中
"terminal.integrated.shell.windows":"C:\\WINDOWS\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [ "/K chcp 65001 >nul"],
保存,重啓 一下vscode就好了
運行程序時終端powshell顯示的編碼設置爲utf-8
和cmd的差不多
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows": ["-NoExit", "chcp 65001"],
保存重啓就好
cmder配置成utf-8
如果要用cmder做終端,目前官方給了兩種方法,一種是替代cmd的,另外一種是替代powershell的,首先介紹cmd怎樣弄,依舊是編輯setting.json文件
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"%CMDER_ROOT%\\vendor\\init.bat"
],
然後在cmder存放目錄下找到vendor文件夾,點進去,右鍵用記事本打開init.bat,在@echo off 後面添加 chcp 65001>nul 保存,重啓vscode就好了。
接下來是powershell的,同理
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy", "Bypass",
"-NoLogo", "-NoProfile", "-NoExit",
"-Command", ". '%CMDER_ROOT%\\vendor\\conemu-maximus5\\\\..\\\\profile.ps1'"
]
%CMDER_ROOT%爲cmder的存放目錄,然後打開%CMDER_ROOT%\vendor\profile.ps1文件,在最後添加
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
保存,重啓vscode就大功告成了。
如果在打開文件後報錯警告:
Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder.
以管理員方式打開powershell,輸入下面命令
Install-Module posh-git -AllowClobber
重啓vscode就好了
不過最好是調debug的編碼格式,可惜不知道怎麼調