在 Visual Studio 代码中更改文件的编码
Change the encoding of a file in Visual Studio Code
有没有办法改变文件的编码?
例如 UTF-8 到 ISO 8859-1?
设置示例 Sublime Text:
"default_encoding": "UTF-8"
下面是如何做到这一点:
在 VSCode 的底部栏中,您会看到标签 UTF-8
。点击它。一种
弹出窗口打开。单击 Save with encoding
。你现在可以选择一个新的
该文件的编码。
或者,您可以使用设置 "files.encoding": "utf8"
在 Workspace/User 设置中全局更改设置。如果使用 VSCode 中的图形设置页面,只需搜索 encoding
。但是请注意,这仅适用于新创建的文件。
除了@DarkNeuron 在回答中解释的设置:
"files.encoding": "any encoding"
您还可以像这样指定特定语言的设置:
"[language id]": {
"files.encoding": "any encoding"
}
例如,当我需要编辑以前使用 ISE 创建的 PowerShell 文件(以 ANSI 格式创建)时,我会使用它:
"[powershell]": {
"files.encoding": "windows1252"
}
现有答案显示了针对单个文件或文件类型的可能解决方案。但是,您可以按照以下路径在 VS Code 中定义字符集标准:
文件 > 首选项 > 设置 > 编码 > 选择你的选项
这将定义一个字符集作为默认值。
除此之外,您随时可以在编辑器右下角(蓝色符号线)为当前项目更改编码。
有没有办法改变文件的编码? 例如 UTF-8 到 ISO 8859-1?
设置示例 Sublime Text:
"default_encoding": "UTF-8"
下面是如何做到这一点:
在 VSCode 的底部栏中,您会看到标签 UTF-8
。点击它。一种
弹出窗口打开。单击 Save with encoding
。你现在可以选择一个新的
该文件的编码。
或者,您可以使用设置 "files.encoding": "utf8"
在 Workspace/User 设置中全局更改设置。如果使用 VSCode 中的图形设置页面,只需搜索 encoding
。但是请注意,这仅适用于新创建的文件。
除了@DarkNeuron 在回答中解释的设置:
"files.encoding": "any encoding"
您还可以像这样指定特定语言的设置:
"[language id]": {
"files.encoding": "any encoding"
}
例如,当我需要编辑以前使用 ISE 创建的 PowerShell 文件(以 ANSI 格式创建)时,我会使用它:
"[powershell]": {
"files.encoding": "windows1252"
}
现有答案显示了针对单个文件或文件类型的可能解决方案。但是,您可以按照以下路径在 VS Code 中定义字符集标准:
文件 > 首选项 > 设置 > 编码 > 选择你的选项
这将定义一个字符集作为默认值。 除此之外,您随时可以在编辑器右下角(蓝色符号线)为当前项目更改编码。