Syntax highlighting causes terrible lag in Vim

EDIT: Blogged about how this all works, with screenshots and awesome-sauce.

https://eduncan911.com/software/fix-slow-scrolling-in-vim-and-neovim.html

Original answer below…


:syntime on

move around in your ruby file and then

:syntime report 

It reported the following slowest matching for me, and you can see that there are not even 1 match.

I disabled rubyPredefinedConstant in ruby.vim file and problem solved. Vim regex engine does not like something in ruby syntax highlight regex. You will have to find the balance between enough syntax highligting and a good performance.

Here is the top 3 slowest syntax highlighting regex for ruby reported on my Mac OS 10.8.5, homebrew Vim 7.4 (console vim)

  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
  3.498505   12494  0       0.008359    0.000280  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!
  2.948513   12494  0       0.006798    0.000236  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!
  2.438253   12494  0       0.005346    0.000195  rubyPredefinedConstant \%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\)\>\%(\s*(\)\@!

Or you can try vim-ruby as pointed out by Dojosto

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)