3

I wanted to highlight all occurence of TODO and NOTE in my code. Looking on the internet, I inserted the following code in my .vimrc

:match GruvboxGreenBold /NOTE/
:2match ErrorMsg /TODO/

This seemed to work fine at first. When I open a file with gvim, the syntax highlights correctly.

However, as soon as I split my screen and the file appears twice, the second one get the correct highlighting but the first one loses it. It repeats whenever I open a new buffer.

Here's a screenshot enter image description here

Does anyone know how to correct this behavior ?

3

From :help :match:

    Note that highlighting the last used search pattern with
    'hlsearch' is used in all windows, while the pattern defined
    with ":match" only exists in the current window.  It is kept
    when switching to another buffer.

It seems that the highlighting created by :match is local to the current window, not to the current buffer. When you split your screen, you create a new window, so you probably have to reapply your highlighting.

If you want :match and :2match to be automatically executed whenever you launch Vim or enter a new window, you could install the following autocmd:

augroup custom_highlighting
    autocmd!
    autocmd VimEnter,WinEnter * match GruvboxGreenBold /NOTE/ | 2match ErrorMsg /TODO/
augroup END
  • Yay ! Works fine with your last workaround ! Thanks a lot ! – Rivten Apr 10 '16 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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