Encoding编码
To display and edit files correctly, WebStorm needs to know which encoding to use. 为了正确显示和编辑文件,WebStorm需要知道使用哪种编码。In general, source code files are mostly in UTF-8. 一般来说,源代码文件大多采用UTF-8格式。This is the recommended encoding unless you have some other requirements.除非您有其他要求,否则这是推荐的编码。
To determine the encoding of a file, WebStorm uses the following steps:为了确定文件的编码,WebStorm使用以下步骤:
-
If the byte order mark (BOM) is present, WebStorm will use the corresponding Unicode encoding regardless of all other settings.如果存在字节顺序标记(BOM),WebStorm将使用相应的Unicode编码,而不考虑所有其他设置。For more information, see Byte order mark.有关更多信息,请参阅字节顺序标记。 -
If the file declares the encoding explicitly, WebStorm will use the specified encoding.如果文件显式声明编码,WebStorm将使用指定的编码。For example, this can apply to XML or HTML files.例如,这可以应用于XML或HTML文件。The explicit declaration also overrides all other settings, but you can change it in the editor.显式声明也会覆盖所有其他设置,但您可以在编辑器中对其进行更改。 -
If there is no BOM and no explicit encoding declaration in the file, WebStorm will use the encoding configured for the file or directory in the file encoding settings.如果文件中没有BOM表和明确的编码声明,WebStorm将使用文件编码设置中为文件或目录配置的编码。If encoding is not configured for the file or directory, WebStorm will use the encoding of the parent directory.如果没有为文件或目录配置编码,WebStorm将使用父目录的编码。If the parent directory encoding is also not configured, WebStorm will fall back to the Project Encoding, and if there is no project, to Global Encoding.如果未配置父目录编码,WebStorm将退回到“项目编码”,如果没有项目编码,则退回到“全局编码”。
Change encoding of a file that contains explicit encoding更改包含显式编码的文件的编码
-
Open the desired file in the editor.在编辑器中打开所需的文件。 -
Change explicit encoding information. Use error highlighting to recognize wrong encoding and press Ctrl+Space to have a list of available encodings displayed:更改显式编码信息。使用错误突出显示可识别错误编码,并按Ctrl+Space可显示可用编码的列表:
Change the encoding used to view a file更改用于查看文件的编码
If WebStorm displays characters in a file incorrectly, it probably couldn't detect the file encoding. 如果WebStorm错误地显示文件中的字符,它可能无法检测到文件编码。In this case, you need to specify the correct encoding to use for viewing and editing this file.在这种情况下,您需要指定用于查看和编辑此文件的正确编码。
-
With the file open in the editor, either select File Encoding widget on the status bar, and select the correct encoding of the file.在编辑器中打开文件后,从主菜单中选择“文件”|“文件属性”|“文件编码”,或单击 from the main menu or click the 状态栏上的“文件编码”小部件,然后选择文件的正确编码。Encodings marked with标记为or
might change the file contents.
或
可能更改文件内容的编码。
In this case, WebStorm opens a dialog where you can choose what to do with the file:在这种情况下,WebStorm会打开一个对话框,您可以在其中选择如何处理文件:-
Reload: load the file in the editor from disk and apply encoding changes to the editor only.重载:从磁盘加载编辑器中的文件,并仅对编辑器应用编码更改。You will see the content changes related to the chosen encoding, but the actual file will not change.您将看到与所选编码相关的内容更改,但实际文件不会更改。 -
Convert: overwrite the file with the chosen encoding.转换:使用所选编码覆盖文件。
-
This will add an association for the file to the file encoding settings. 这会将文件的关联添加到文件编码设置中。WebStorm will use the specified encoding to view and edit this file.WebStorm将使用指定的编码来查看和编辑此文件。
Configure default encoding for properties files为属性文件配置默认编码
WebStorm applies system default encoding to .properties files. WebStorm将系统默认编码应用于.properties文件。To use other encodings, feed them as escape sequences and Unicode. 要使用其他编码,请将其作为转义序列和Unicode提供。Alternatively, define the default encoding for .properties files on the project level and use different API that can read .properties files in the encoding you have defined.或者,在项目级别定义.properties文件的默认编码,并使用不同的API来读取已定义编码中的.properties文件。
-
In the Settings/Preferences dialog Ctrl+Alt+S, select .在“设置/首选项”对话框中,按住Ctrl+Alt+S键,选择“编辑器”|“文件编码”。 -
Do one of the following:执行以下操作之一:-
To have the special mode turned on when symbols are stored in a properties file as escape sequences but displayed as normal letters, check the option Transparent native-to-ascii conversion.当符号作为转义序列存储在属性文件中但显示为普通字母时,要启用特殊模式,请选中“透明本机到ascii转换”选项。This option is helpful when the properties files are encoded in ISO 8859-1.当属性文件以ISO 8859-1编码时,此选项非常有用。It is recommended to use this approach, if you don't have any special reasons to change encoding.如果您没有任何特殊原因更改编码,建议使用这种方法。 -
In the Default encoding for properties files list, select the encoding that will be used for all properties files in project.在“特性文件的默认编码”列表中,选择将用于项目中所有特性文件的编码。
-
Configure file encoding settings配置文件编码设置
In the Settings/Preferences dialog Ctrl+Alt+S, select .在“设置/首选项”对话框Ctrl+Alt+S中,选择“编辑器”|“文件编码”。
WebStorm uses these settings to view and edit files for which it was not able to detect the encoding and also uses the specified encodings for new files.WebStorm使用这些设置来查看和编辑无法检测编码的文件,并且还将指定的编码用于新文件。
| |
| |
| |
| |
|
Select console output encoding选择控制台输出编码
By default, WebStorm uses the system encoding to view console output.默认情况下,WebStorm使用系统编码来查看控制台输出。
-
In the Settings/Preferences dialog Ctrl+Alt+S, select .在“设置/首选项”对话框Ctrl+Alt+S中,选择“编辑器”|“常规”|“控制台”。 -
Select the default encoding from the Default Encoding list.从“默认编码”列表中选择默认编码。 -
Click OK to apply the changes.单击“确定”应用更改。