I'm trying to write a plugin to highlight overused words in a file. After this question I now have a way to highlight the most frequent words in each paragraph.To restrict the highlighting of a word to a single paragraph I'm using matchadd with a line range:matchadd('Error', word . '\%>' . (a:firstline - 1) . 'l\%<' . (a:lastline + 1) . 'l')The problem is that if the user adds or removes a line in the middle of a file it messes up the highlighting of the following lines.So how can I keep the highlighting up to date after changes in the file?My first thought is to just clear the previous matches and highlight everything all over again when a line is added or removed. Is there no better way to do it? If there isn't, how can I detect if a line was added or removed so I can clear the matches and add them again?
Keep matchadd and matchaddpos up to date after file changes
vimscript;highlight