Helpful VIM highlighting

Here’s a quick snippet that you can add to your .vimrc in order to get:

  • MS Visual Studio-like ‘current word‘ highlighting.
  • Trailing space highlighting.

The result looks like this:

vim_hl

And the code is:

function Matches()
    highlight curword ctermbg=white ctermfg=black cterm=bold gui=bold guibg=darkgrey
    try
        call matchdelete(w:lastmatch)
        unlet w:lastmatch
    catch
    endtry
    silent! let w:lastmatch=matchadd ('curword', printf('\V\<%s\>', escape(expand(''), '/\')), -1)
    highlight eolspace ctermbg=red guibg=red
    2match eolspace /\s\+$/
endfunction
au CursorMoved * exe 'call Matches()'

Yes, one day I might convert it to a vim plugin, meanwhile just copy-paste to your .vimrc.

Enjoy!

Tags: [en] | January 31st, 2013 |

One Response to “Helpful VIM highlighting”

  1. Joy Says:

    Awesome!

Leave a Reply