I have the following in ~/.vim/ftplugin/python.vim to highlight long lines, accidental tabs and extra whitespace in Python files:
hi CustomPythonErrors ctermbg=red ctermfg=white guibg=#592929
au BufWinEnter *.py call matchadd('CustomPythonErrors', '\%>80v.\+', -1)
au BufWinEnter *.py call matchadd('CustomPythonErrors', '/^\t\+/', -1)
au BufWinEnter *.py call matchadd('CustomPythonErrors', '\s\+$', -1)
au BufWinLeave *.py call clearmatches()
The BufWinLeave is so that the matches are cleared when I switch to another file in case that file isn't a .py file. It's an essential feature for me when working with something like Django.
It all works fine for random amounts of time; from ten minutes to hours (my guess is it depends on how many files I open/close). But eventually when any line over 80 characters is displayed GVim slows to a halt and requires a restart.
Does anyone have any ideas why this would eventually slow down?