Search code examples
vimmatchsyntax-highlightinghighlight

Why does defining new match in Vim remove the previously defined one?


To show trailing whitespace in Vim, I use the following:

highlight whitespaceEOL term=reverse ctermbg=Grey guibg=Grey
match whitespaceEOL /\s\+\(\%#\)\@!$/

When I use the following match for long lines, the first match is lost:

augroup longLines
    autocmd! filetype zsh,sh,python,vim,c,cpp :match ColorColumn /\%>80v.\+/
augroup END 

Why is that happening?


Solution

  • :match only matches one pattern at a time. :2match and :3match exist for exactly this reason. Try this:

    2match whitespaceEOL /\s\+$/
    3match ColorColumn /\%>80v.\+/
    

    Alternatively, you can implement this as syntax. Try this:

    syntax match whitespaceEOL /\s\+$/
    syntax match ColorColumn /\%>80v.\+/