Introduction
Vim show line endings usually means you need to confirm whether a file uses LF, CRLF, or a broken mix of both. Vim can tell you the current file format quickly, and it can also make hidden line ending characters visible so you can clean the file without guessing.
Symptoms
- A script works on one system but fails on another
- Git or CI reports line ending changes you did not expect
- Shell scripts show
^Merrors on Linux - A file looks normal in Vim until you inspect whitespace
Common Causes
- A file moved between Windows and Linux environments
- An editor or Git setting rewrote endings during save or checkout
- The file contains mixed
LFandCRLFendings - You are checking the buffer visually without enabling whitespace display
Step-by-Step Fix
- 1.Check the current file format
- 2.Vim can tell you whether the current buffer is using
unix,dos, ormacline endings.
:set fileformat?- 1.Make line endings visible
- 2.Turn on list mode and display the end-of-line marker explicitly.
:set list
:set listchars=eol:$,tab:>-,trail:-- 1.Search for carriage returns in mixed files
- 2.If a file is inconsistent, search for
\rcharacters directly.
/\r$- 1.Convert the file to the format you want
- 2.Set the target format and write the file back out.
:set fileformat=unix
:wPrevention
- Keep Git line ending policy explicit across platforms
- Check
fileformatbefore editing files from mixed environments - Use visible whitespace when debugging shell, config, or CI problems
- Normalize line endings before large refactors or generated file updates