Wrong diacritic letters in Integrated Terminal of Visual Studio Code with PowerShell between Run and Run Selection

Viewed 191

I have the Windows 10 with Windows-1250 encoding but in Visual Studio Code with integrated terminal I have problems with diacritic signs:

enter image description here

As you see encoding is different between Run and Run Selection of same command: write-host "Wspólny" My JSON user configuration is empty, I've been trying for several hours but no solution helps. I want UTF-8 everywhere.

1 Answers

The most likely explanation:

  • You're running Windows PowerShell, which reads its source code based on the system's active ANSI code page (1250 in your example).

  • By contrast, Visual Studio Code creates BOM-less UTF-8-encoded files by default.

  • In the absence of a BOM in a source code file (or any text file that Windows PowerShell reads, such as with Get-Content), ANSI encoding is assumed, so the UTF-8 file is misinterpreted.

    • Specifically, each individual byte of any non-ASCII character - which in UTF-8 is always encoded as a multi-byte sequence - is then interpreted as an ANSI character.

    • Note: This is no longer a problem in PowerShell (Core) 7+, which consistently defaults to UTF-8, both on reading BOM-less files and when writing files (BOM-less UTF-8).

Therefore, the solution is to save your source code - or any UTF-8 files you want Windows PowerShell to read correctly - as UTF-8 with BOM.

You also need to do this for source code you want to run properly in both editions of PowerShell.

Related