Как изменить кодировку в vs code
Перейти к содержимому

Как изменить кодировку в vs code

  • автор:

Программирование на C, C# и Java

Уроки программирования, алгоритмы, статьи, исходники, примеры программ и полезные советы

ОСТОРОЖНО МОШЕННИКИ! В последнее время в социальных сетях участились случаи предложения помощи в написании программ от лиц, прикрывающихся сайтом vscode.ru. Мы никогда не пишем первыми и не размещаем никакие материалы в посторонних группах ВК. Для связи с нами используйте исключительно эти контакты: vscoderu@yandex.ru, https://vk.com/vscode

Проблемы с кодировкой кириллицы в консоли. Смена кодировки

Зачастую у программистов появляются проблемы с русским языком в консоли при загрузке в неё текстового файла — вместо кириллицы появляются какие-то непонятные символы или вопросительные знаки. Данная проблема очень легко решается — нужно просто сменить кодировку файла на UTF-8 или на Юникод (либо на какую-либо другую, с которой консоль заработает). Как это сделать, вы узнаете в нашей статье. Итак, если у вас в консоли вместо кириллицы написано что-то похожее на символы с нижнего изображения, либо просто непонятный набор неизвестных символов, то всё дело в неправильной кодировке файла.

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

Исправить данную проблему не составит труда.

Проблемы с кодировкой кириллицы в блокноте

У каждого на компьютере имеется блокнот — самый простой помощник в данной проблеме. Всё, что нам надо — это открыть «сломанный» файл в блокноте (главное, чтобы в нём русский язык отображался правильно, иначе придётся заново переписывать текст), затем нажать в блокноте вкладку «Файл», а затем «Сохранить как…». В низу появившегося окна можно будет найти надпись «Кодировка» с комбобоксом, в котором Вам надо выбрать UTF-8 либо Юникод (это почти одинаковые кодировки, но если одна из них не заработает, то выбирайте вторую).

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

После сохранения файла попробуйте запустить консоль ещё раз, всё должно заработать.

Проблемы с кодировкой кириллицы в WordPad

Текстовым редактором WordPad также можно починить файл. Делается это идентично способу с блокнотом. Опять надо файл «Сохранить как…», однако выбор кодировки здесь не задан отдельно, как в блокноте, а вынесен в «Тип файла».

Нам нужно выбрать тип «Текстовый документ в Юникоде» и таким образом сохранить файл.

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

Проблемы с кодировкой кириллицы в Visual Studio

Вариант 1. Изменение кодировки файла.

Если ваш файл открыт у вас в Visual Studio, то для смены кодировки нужно выполнить следующие действия: В рабочей среде кликнуть на вкладке файла:

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

Затем перейди в меню «Файл» -> «Дополнительные параметры сохранения..».

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

В появившемся окне смотрим огромный список с названием «Кодировка» и выбираем там Юникод:

Проблемы с кодировкой кириллицы в консоли. Смена кодировки - vscode.ru

После нажимаем «ОК», и всё готово!

Вариант 2. Изменение кодировки программно.

Кроме того, в Visual Studio можно легко поменять кодировку файла в самом коде. Делается это, на примере работы с классом StreamReader, вот так:

How to Change File Encoding in VS Code (2 approaches)

This article shows you 2 different ways to change file encoding (UTF-8, UTF-8 with BOM, UTF-16 LE, ISO, DOS, Arabic, Japanese, etc) in VS Code (Visual Studio Code). The first approach works for a single file, and the second one can be used for the workplace or at the user level.

Change Encoding for a Single File

The settings below only apply to a single code file. Other files in your project will stay with the current encoding. Advertisements

1. Head to the bottom bar and click on UTF-8:

2. Select Reopen with Encoding or Save with Encoding (based on your need):

3. Select an encoding standard from the list:

Advertisements And your file will be saved/opened with the newly selected encoding.

Demo:

Change File Encoding Globally

The steps below affect every newly created file (but do not affect the old files). Advertisements

1. Go to the Settings area of VS Code:

  • Mac: Code > Preferences > Settings (hotkeys: Command + ,)
  • Windows: File > Preferences > Settings (hotkeys: Ctrl + ,)

2. Type “encoding” into the search field, head to the Files: Encoding section, and select what you want from the drop-down. See the following screenshot for more clarity:

Your change will be automatically saved.

Conclusion

You’ve learned how to change file encoding in VS Code. If you’d like to explore more new and useful stuff about this awesome IDE, take a look at the following articles:

You can also check out our Visual Studio Code topic page for more tips and tricks to improve your producibility and coding experience.

VScode — Encoding

In this tutorial, You learn how to change the VSCode encoding to (UTF-8, UTF-16, ANSI, ISO-8859-1, Arabic, Japanese), Set encoding for a single file for reopening and save and global encoding permanently.

In this tutorial, You learn how to change the VSCode encoding to (UTF-8, UTF-16, ANSI, ISO-8859-1, Arabic, and Japanese)

  • Change encoding to the opened file
  • Update encoding permanently and globally in VSCode

What is the default encoding for Visual studio code? The default encoding is UTF-8. you can change it

Please enable JavaScript

How to change encoding for an open file in VS Code

In this approach, You can change the encoding for a single file or opened file.

Open a file in Visual Studio Code, If the file is not opened, The below option is not visible

You will see the UTF-8 text in the bottom bar of the Visual studio code

Visual Studio Code (VSCode) change encoding

  • Clicking on the UTF-8 label, you will see two options as seen below

Visual Studio Code (VSCode) change encoding

Select One of the options below

  • Reopen with Encoding- The file is reopened with the selected encoding
  • Save with Encoding — The file is saved with selected encoding. you can choose one of the options from above.

Visual Studio Code (VSCode) encoding list

you can select one from the list i.e Japanese or Korean or your required one.

That’s it, the file will be opened or saved with the selected encoding

This approach only works for a single file.

What is the shortcode to change the encoding in VSCODE? Alternatively, you can change the encoding with a single file for the below command CTRL+SHIFT+P command and type encoding and select Reopen or save with encoding option

Set Encoding globally in Visual Studio Code

In Windows, you can select File -> Preferences -> Settings Alternatively, you can open using short keys( CTRL + , ) Command

In MAC:- Code -> Preferences -> Settings Alternatively, you can open using short keys( Command +, ) Command

It opens a settings window and types encoding and changes the default encoding from a given list on the Files: Encoding option as seen below

Visual Studio Code (VSCode) Globally Encoding set

This changes encoding globally in VSCode and newly created files will be saved with the new encoding.

Change the encoding of a file in Visual Studio Code

Is there any way to change the encoding of a file? For example UTF-8 to ISO 8859-1?

Setting Example Sublime Text:

Fernando Tholl's user avatar

3 Answers 3

So here’s how to do that:

In the bottom bar of VSCode, you’ll see the label UTF-8 . Click it. A popup opens. Click Save with encoding . You can now pick a new encoding for that file.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *