Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Encoding RulesNew to Visual Studio Code? Get it now.
Encoding Rules

Encoding Rules

Productivity++

|
64 installs
| (0) | Free
| Sponsor
Fix garbled text in VS Code: set encoding rules once per folder or path pattern
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Encoding Rules

Fix garbled text in VS Code: set encoding rules once per folder or path pattern

Seeing � or é in your files? VS Code can't always detect legacy encodings (Windows-1252, Windows-1257, Shift-JIS, GBK…), so text ends up garbled.

Encoding Rules lets you assign an encoding to a file, folder or glob pattern. Set it once, and the file opens correctly every time, with no more File → Reopen with Encoding.

Ideal for legacy codebases, imported files, and repositories that mix UTF-8 with older encodings.

Encoding Rules Demo

Quick Start

  1. Open a file that shows garbled text.
  2. Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and run Encoding Rules: Create Rule for Current Folder (or ...for Current File).
  3. Pick the encoding. From now on, matching files open with it.

Why not just use VS Code's auto-detection?

VS Code can guess encodings (files.autoGuessEncoding), but it's a statistical guess: it can pick the wrong encoding, and the list of encodings you can prioritize with files.candidateGuessEncodings doesn't include every encoding.

Encoding Rules takes a different approach: you decide once, and it's applied every time, for any encoding VS Code can open.

Features

  • Applies your chosen encoding automatically whenever a matching file is opened.
  • Matches by file path using glob patterns: a single file, a folder, or a whole tree.
  • Keeps a legacy folder in, say, Windows-1257 while the rest of your repo stays UTF-8.
  • Resolves overlapping rules predictably: the most specific rule wins.
  • Shows a status bar indicator, so you can see how a rule relates to the current file and fix it in one click.
  • Stores rules in a regular VS Code setting (encodingRules.rules), so you can also edit them by hand.

Commands

Encoding Rules provides the following commands through the VS Code Command Palette.

Command Description
Encoding Rules: Create Rule for Current File Creates an encoding rule for the currently active file. Choose an encoding from the list or enter a custom encoding. If a matching rule already exists, you can replace it.
Encoding Rules: Create Rule for Current Folder Creates an encoding rule for the folder containing the currently active file. The rule applies to files matching that folder path.
Encoding Rules: Show Matching Rule Shows the encoding rule currently matching the active file, including the encoding and matching path pattern.

Open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS) and search for Encoding Rules.

Status Bar Indicator

An Encoding Rule item appears in the status bar, near VS Code's own encoding indicator, whenever it has something useful to tell you about the active file.

Indicator Meaning Click to
✓ Encoding Rule A rule matches, and the file uses its encoding See the matching rule
⚠ Encoding Rule A rule matches, but the file is open in a different encoding Follow the rule, update the rule to match the file, or show the rule
+ Encoding Rule No rule matches, and the file isn't in your default encoding Save the current encoding as a rule for the folder or for this file only
⊘ Encoding Rule A rule matches, but the file is above the size limit, so the rule was skipped See details

Found the right encoding with Reopen with Encoding? Click + Encoding Rule to keep it as a rule.

Use the encodingRules.statusBar setting to show the indicator for every file (always) or hide it (never).

Status Bar Indicator

Configuration

Add encoding rules in your VS Code settings:

{
  "encodingRules.rules": {
    "windows1257": [
      "**/legacy/**"
    ],
    "shiftjis": [
      "**/jp-import/**"
    ]
  }
}

The setting is an object where:

Part Description
Key The encoding to use when opening matching files (e.g. windows1257, utf8, shiftjis)
Value An array of glob patterns. Files whose path matches any of them are opened with that encoding

In the example above, files in legacy open as Windows-1257, and files in jp-import open as Shift-JIS.

Rule priority

If more than one rule matches a file, the most specific rule wins: the matching pattern with the most characters takes priority, regardless of the order in your settings.

For example, if you also had a rule for **/*.txt, the file legacy/notes.txt would still open as Windows-1257, because **/legacy/** is the longer pattern. To make a rule win over another, make its pattern more specific.

Pattern matching is case-insensitive, and Windows-style backslashes in paths are handled automatically. Not sure which rule applies to a file? Run Encoding Rules: Show Matching Rule.

Other settings

Setting Default Description
encodingRules.statusBar auto When to show the status bar indicator. auto shows it when a rule matches the file or the file isn't in your default encoding, always shows it for every file, never hides it.
encodingRules.maxFileSize 52428800 (50 MB) Largest file size, in bytes, to which rules are applied. Larger files are skipped.
encodingRules.showLargeFileWarning true Show a warning when a file matching a rule is skipped for being too large. You can also turn it off with Don't Show Again on the warning itself.

Lowering encodingRules.maxFileSize is useful if you want to skip large files that are slow to reopen. Raising it above about 50 MB may have no effect, because VS Code may not make very large files available to extensions.

Supported Encodings

Supported encodings depend on VS Code's built-in encoding support. Use VS Code's encoding IDs (for example windows1252, not windows-1252). The Create Rule commands let you pick from a list, so you don't have to memorize them.

Common examples:

Encoding ID Typically used for
utf8, utf8bom Unicode text (with or without BOM)
windows1252 Western European languages
windows1250 Central European languages
windows1251 Cyrillic (Russian, Ukrainian, Bulgarian…)
windows1257 Baltic languages (Latvian, Lithuanian, Estonian)
shiftjis Japanese
gbk, gb18030 Simplified Chinese
cp950, big5hkscs Traditional Chinese
euckr Korean

Glob Patterns

Rules use glob patterns to match files.

Pattern Matches
**/*.txt All .txt files
**/legacy/** All files inside folders named legacy
src/**/*.c C files inside src and its subfolders

Known Limitations

  • Encoding detection is not performed. Rules are based on file paths.
  • Incorrect rules may cause files to be opened with the wrong encoding.
  • Some VS Code internal documents may not have normal file paths.
  • The extension does not modify file contents; it only controls how files are opened.
  • If you manually choose Reopen with Encoding, VS Code keeps that choice until the file is closed. The next time the file opens, your rule applies again.
  • Large files are skipped. The default limit is 50 MB, and you can lower it with encodingRules.maxFileSize.

Support

If Encoding Rules saves you time, consider supporting development:

Buy Me a Coffee GitHub Sponsors

License

MIT License

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft