Hiding carriage returns (^M)

1 Point

Gregory Pakosz Gregory Pakosz

10 years ago

Sometimes, you end up editing files with mixed line endings.

You would like to have less visual distraction by removing those ^M Vim displays.

Yet you don't want to convert the whole file to LF or CRLF (for various reasons like not creating meaningless diffs in the SCM).

Find more in my .vimrc: https://github.com/gpakosz/.vim

for i in ['cterm', 'gui']
  for j in ['fg', 'bg']
    let c = synIDattr(hlID('Normal'), 'bg', i)
    if (!empty(c))
      exec 'highlight CarriageReturn ' . i . j . '=' . c
    endif
  endfor
endfor
if hlID('CarriageReturn')
  match CarriageReturn /\r$/
endif