问题
I recently started to use Visual Studio Code on Server Systems where I did not have Studio IDE installed. I like it very much but run into a problem.
When I open a file (used Notepad++ before) the editor detect encoding and set it for me. Have many files on windows servers with windows-1252
still but vscode
just use UTF-8
by default.
I know I can reopen with encoding Western (Windows 1252)
but I forgot it often and I sometimes destroyed some content saving it.
So I did not find any parameter yet, is there a way to make vscode
detect encoding and set it automatically when I open a file?
回答1:
To allow Visual Studio Code to automatically detect the encoding of a file, you can set "files.autoGuessEncoding":true
(in the settings.json
configuration file).
https://github.com/Microsoft/vscode/pull/21416
This obviously requires an updated verison of the application compared to when the question was originally asked.
回答2:
- Go to
File
->Preferences
->User Settings
- Add (or update) the entry
"files.encoding": "windows1252"
to the right editor window and save
Now VSCode opens all text files using windows-1252
when there is no proper encoding information set.
EDIT:
In 2017's June release the files.autoGuessEncoding
setting was introduced. When enabled it will guess the file's encoding as good as possible. Its default value is false
.
来源:https://stackoverflow.com/questions/38528384/how-to-setup-visual-studio-code-detect-and-set-correct-encoding-on-file-open