vimtricks.wiki Concise Vim tricks, one at a time.

How do I re-open a file in Vim with a specific encoding without restarting?

Answer

:e ++enc={encoding}

Explanation

When Vim auto-detects the wrong character encoding — mojibake where é shows as é is a classic symptom — you can reload the current buffer with a specific encoding using the ++enc flag. This reloads the raw bytes from disk and re-interprets them without leaving Vim or losing your window layout.

How it works

  • :e (:edit) reloads the current file
  • ++enc={encoding} is a one-time override that tells Vim which encoding to use when reading the file
  • Common values: utf-8, latin1, cp1252, iso-8859-1, utf-16, utf-16le
  • The ++enc flag does NOT permanently change fileencoding — it only affects this reload

Example

You open a Windows-1252 file and see garbled characters:

Café au lait

Reload with the correct encoding:

:e ++enc=cp1252

Now it reads correctly:

Café au lait

To also save it as UTF-8 (converting the encoding), use :w with ++enc:

:w ++enc=utf-8

Or set fileencoding and write normally:

:set fileencoding=utf-8
:w

Tips

  • Pair with ++ff=unix to also fix line endings: :e ++enc=utf-8 ++ff=unix
  • :set fileencodings controls the auto-detection order — add latin1 as a last-resort fallback
  • In Neovim, :checkhealth can help diagnose encoding-related issues

Next

How do I define a mapping that only takes effect if the key is not already mapped?