How do I reopen the current file and force Vim to interpret it with a specific line ending format?
Answer
:e ++ff=unix
Explanation
The ++ff modifier forces Vim to re-read the current file from disk using a specific fileformat — unix (LF), dos (CRLF), or mac (CR). This is different from :set fileformat=unix, which only affects how Vim will write the file; ++ff actually re-parses the existing bytes on disk.
How it works
:e ++ff=unix— reloads the current file treating all line endings as LF:e ++ff=dos— reloads treating CRLF as the line separator:e ++ff=mac— reloads treating bare CR as line separators (classic Mac)- The
++ffoverride only affects this one:ecommand; it doesn't permanently changefileformat
Example
You open a Windows file and see ^M characters at the end of every line (CRLF read as unix). Fix it:
:e ++ff=dos
Vim re-reads the file treating \r\n as the line separator, so the ^M characters disappear. Then save with unix endings:
:set fileformat=unix
:w
Tips
- Combine with
++encto re-open with both a specific encoding and fileformat::e ++ff=unix ++enc=utf-8 - If the file has unsaved changes, use
:e! ++ff=unixto force the reload (discards changes) - View the detected format after opening:
:set fileformat? - To convert a file's endings without reopening, use
:set fileformat=unix | w