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 ^M errors 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 LF and CRLF endings
  • You are checking the buffer visually without enabling whitespace display

Step-by-Step Fix

  1. 1.Check the current file format
  2. 2.Vim can tell you whether the current buffer is using unix, dos, or mac line endings.
vim
:set fileformat?
  1. 1.Make line endings visible
  2. 2.Turn on list mode and display the end-of-line marker explicitly.
vim
:set list
:set listchars=eol:$,tab:>-,trail:-
  1. 1.Search for carriage returns in mixed files
  2. 2.If a file is inconsistent, search for \r characters directly.
vim
/\r$
  1. 1.Convert the file to the format you want
  2. 2.Set the target format and write the file back out.
vim
:set fileformat=unix
:w

Prevention

  • Keep Git line ending policy explicit across platforms
  • Check fileformat before 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