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
++encflag does NOT permanently changefileencoding— 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=unixto also fix line endings::e ++enc=utf-8 ++ff=unix :set fileencodingscontrols the auto-detection order — addlatin1as a last-resort fallback- In Neovim,
:checkhealthcan help diagnose encoding-related issues