Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance on highlighting words/lines in Vim
    primarykey
    data
    text
    <p>I have a set of small functions in VimL highlight a line (or a word) depending on certain conditions.</p> <p>You should consider the workings of the functions to act similar as the spelling (<code>:set spell</code>), underlining when the conditions are met.</p> <p>I have found, however, that when the number of highlighted lines exceed about 75, there is a significant lag when moving. Either from side to side or up or down.</p> <p>I had some convenient <code>AutoCommands</code> that I was enabling by default, (for example, to echo why the line is highlighted) but even with all of them disabled, as soon as I call the function that highlights everything, I can tell there is a huge lag.</p> <p>This is what I am using to highlight a word:</p> <pre><code>call matchadd('MyCheck', '^\%'. line . 'l\_.\{-}\zs\k\+\k\@!\%&gt;' . column . 'c') </code></pre> <p>And this is what I use to highlight the whole line</p> <pre><code>call matchadd('MyCheck', '\%' . line . 'l\n\@!') </code></pre> <p>The 75 number I use as a reference for determining a lag is just a reference, it is a bit of a sweet spot for me, but just to demonstrate that most anything beyond gets increasingly worse.</p> <p>I also use the <code>SpellBad</code> highlighting for <code>MyCheck</code>, but seriously doubt that this causes any problems.</p> <p>Is there something I could do differently to avoid the lag? Is <code>matchadd</code> the best option?</p> <p>EDIT: Just to make sure it is not any of my functions or code doing something weird, I opened a 500 line file and did this:</p> <pre><code>highlight link MyCheck SpellBad for line in range(line('$')) call matchadd('MyCheck', '\%' . line . 'l\n\@!') endfor </code></pre> <p>Which basically highlights every single line on the file. Everything clearly got impossibly slow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload