Is there anything I can do to keep syntax on when using Vim?

As soon as I open anything substantial it becomes nearly impossible to edit after a while. Every keypress causes a delay. If I turn syntax highlighting off or relaunch vim – it is fine again.

I have synmaxcol set to 120. Sample ruby file is only 59 lines long and not exceeding 80 characters.

I am using vim-ruby and vim-rails.

The problem is that the delay seem to accumulate over time. When I open the file from scratch it is fine. After a while it gets slower and slower.

  • 1
    Have you tried replicating this with vim -Nu NONE -c 'syntax on'? Have you followed the debugging tips on this post – akshay Apr 10 '15 at 6:28
  • What filetype? Any? – romainl Apr 10 '15 at 7:07
  • 1
    Ruby. Indeed it is editable with -u NONE so it must be some plugin then. Guess the answer to most questions is 'disable plugins until you find the culprit' :( – firedev Apr 10 '15 at 8:03
  • But the problem is - the delay seems to accumulate over time. When I open the file from scratch it is fine. After a while it gets slower and slower. – firedev Apr 10 '15 at 8:06

Recent Vim versions have a :syntime command to troubleshoot slowness of syntax highlighting by generating a report of how long each syntax group takes to match. This is very helpful and quickly lets you find the culprit; the only downside is that you need a (usually "HUGE") build of Vim with profiling enabled. :help :syntime provides good instructions how to employ it.

Alternatively, you can try removing individual syntax scripts from ~/.vim/syntax/ and $VIMRUNTIME/syntax/ (according to the current 'filetype'), and then further drill down by removing parts of the syntax definitions inside the script.

  • Hmm interesting, sounds like this is something tags related. The top line that takes the most time has methods from my other projects. TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN 0.129674 247 182 0.002365 0.000525 rubyMethodNameTag \C\<\%(roi\|paginate\|admin_index_attributes\|facilities\|manager\|net_price?\ .... – this is clearly from the other folder. Disable tags? – firedev Apr 10 '15 at 8:24
  • Do you use a plugin that highlights tags, such as vim-easytags? That might indeed cause the slowdown. – Ingo Karkat Apr 10 '15 at 8:27
  • Yep, disabled it, not the numbers are sane again. Thanks. – firedev Apr 10 '15 at 8:29
  • Hmm now it's acting up again, this time its: 0.121880 2078 54 0.002260 0.000059 rubySymbol []})\"':]\@<!\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],]\@= – Anything I can do about it? – firedev Apr 10 '15 at 9:42
  • 1
    It might be the new regexp engine; try :set regexpengine=1 (best in a new Vim instance, before opening the Ruby file). – Ingo Karkat Apr 10 '15 at 9:54

Another typical bottleneck in vim's syntax highlight is folding. Editing can become very slow if a fold contains many syntax items (which basically means it goes over many lines), because vim will refresh all syntax for every inserted character.

If this is what you are experiencing then I suggest the use of FastFold plugin. This plugin identifies syntax folds and replaces them with manual folds, making vim's syntax highlight much faster.


Here is what I did in the end:

  • Removed xolox/vim-easytags
  • Removed xolox/vim-misc
  • Replaced kien/ctrlp d11wtq/ctrlp_bdelete and tacahiroy/ctrlp-funky with junegunn/fzf
  • Set regexpengine=1

Right now Vim is smooth like butter but I don't have tags anymore. Sigh...

  • 1
    Vim has tags support built-in. You don't need any third-party plugins (other than ctags to generate the tags file of course). See Effortless Ctags With Git article by Tim Pope. I use this and it works wonders. Also see :help tag-commands to jump to a tag. I consider ctags pretty essential when working with Vim. It makes navigation super simple, and you can even autocomplete with :help i_Ctrl-x_Ctrl-]! – akshay Apr 12 '15 at 9:41
  • Care to add anything here vi.stackexchange.com/questions/2630/how-to-set-up-tags-properly ? – firedev Apr 12 '15 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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