1

I was trying to learn javascript the other day and was using emacs as I have been trying to learn emacs as well. But after sometimes my left wrist started to hurt(as one's does) so I switched to neovim and noticed a significant amount of lag in html files with document.write(); statements for some reason. I turned off the syntax highlighting and the lag was gone. I am using joshdick/onedark.vim colorscheme. I thought about changing into some other colorscheme, but I would rather stay in this one as my all other resources use the same colorscheme.

Any idea how to cope with this?

2
  • Unless the colorscheme is defining its own syntax rules (blech), the lag is likely from a slow regex in a syntax file. Do you have javascript syntax files other than those from the standard distribution?
    – D. Ben Knoble
    Feb 25, 2018 at 9:35
  • I have vim-polyglot. Disabling it removes the lag. Can you explain why it caused this scenario? I don't know about regex, I mean I know what it is but I don't know it's use in vim. So, should I just not use vim-polyglot? I don't use it exclusively, I just somewhere picked it up. @DavidBenKnoble
    – 3N4N
    Feb 25, 2018 at 11:30

1 Answer 1

1

Vim-polyglot

vim-polyglot contains what it calls 'language packs', which are sets of syntax, ftplugin, and other files that 'enhance' the experience of working with a particular language. These files work as explained by the help reference, in particular at :help rtp and various topics like syntax, ftplugin, &c.

Regexes/syntax

Regexes are common to syntax files as a way to define for Vim that, say, var is a keyword and 123 is a constant. If a regex is 'slow', it will slow down syntax highlighting.

By 'slow' I mean that vim's regex engine has a hard time handling it efficiently; this is always a known limitation of regexes, although for the most part vim handles them quite well.

Fixes

  • Suffer through slowness (but this is Vim, not emacs, so I'm going to guess you don't want that)
  • Turn off syntax highlighting (apparently there is a trend of people doing this to focus better?)
  • Remove your vim-polyglot (consider filing a bug related to your specific language js)
    • If they then fix the bug, you can reuse the plugin

Lacking the time and effort to fully explain syntax files/the runtime path, I'm going to point any curious readers to here (thank you Steve Losh). In fact, if you haven't already, the whole book there is a good read.

2
  • In your 2nd point under "Fixes", did you want to say "Turn off syntax highlighting" ?
    – 3N4N
    Feb 26, 2018 at 5:43
  • Indeed. Will edit
    – D. Ben Knoble
    Feb 26, 2018 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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