I would like to set a different highlighting for windows EOL characters.

I have tried several approaches and some of them worked when I did : so $MYVIMRC, which is pretty strange, because after I closed and reopened a file these effects were gone.

I tried:

call matchadd("NewLineWin", "\r\n")

call matchadd("NewLineWin", "\r\(\n\)\@=")

call matchadd("NewLineWin", "\r(?=\n)")

And none of these worked after reopening the file.

There is no error in the highlight setting, because, if I change the matchadd call to this call matchadd("NewLineWin", "\r") everything works normally. But I doubt that this is an acceptable approach, since Windows EOL are \r\n and not simply \r. Besides, I'm wondering what is wrong with my regex.

Could anyone help me with this, please?

  • Just add [%{&ff}] to your 'statusline'. Newlines are represented by, well, new lines in Vim.
    – Antony
    Jul 26, 2016 at 14:47
  • @Antony sorry, I didn't get it, how it is supposed to highlight characters \r\n at the and of a line ? I did this and saw no difference.
    – d.k
    Jul 26, 2016 at 15:31
  • 2
    It doesn't, it tells you in your statusline what the line endings are. Line endings in vim are represented by a linebreak. If you have 'set ffs=unix' and load a DOS file, you'll have a bunch of ^M characters at the end of each line, highlighted with the SpecialKey group. Pretty hard to miss.
    – Antony
    Jul 26, 2016 at 15:55

1 Answer 1


One must use the dollar $ sign which marks eol in regex expressions which are not in the multiline mode.

That is the substitution of \n to $ in the first example call matchadd("NewLineWin", "\r$") did the work.

This solution for some yet unknown reason does not work when one opens a file in a new tab, that is when vim is already running

  • 1
    Note that this will only ever match something if the file has mixed line endings.
    – jamessan
    Jan 18, 2016 at 19:37
  • @jamessan, do you mean a file which is edited in vim without the ffs option set to unix? Right now I checked a file, which had only windows eol (that is no mix) and everything was highlighted fine. I suppose that the ffs option is relevant here, because only with it I have managed to show carriage return characters.
    – d.k
    Jan 19, 2016 at 6:54
  • Ah, so you're specifically setting 'ffs' in such a way that Vim will never detect a file as having dos line endings, so that you can highlight them? Why not just put something in your statusline to show what the fileformat is, so you know when it's dos vs. unix?
    – jamessan
    Jan 19, 2016 at 14:39
  • @jamessan, I actually don't know what can I put into the status line, in this case, I'm very new to vim. I just always work with "unix" files, but sometimes it can happen that windows eols are used (which is not proper in my environment) by someone else, so I wanted a way to spot such situations immediately.
    – d.k
    Jan 19, 2016 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.