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

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 ++ff override only affects this one :e command; it doesn't permanently change fileformat

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 ++enc to re-open with both a specific encoding and fileformat: :e ++ff=unix ++enc=utf-8
  • If the file has unsaved changes, use :e! ++ff=unix to 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

Next

How do I add a visual indicator at the start of soft-wrapped continuation lines to tell them apart from real line starts?