Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Mac)Vim quite slow when syntax is set to Ruby

Tags:

vim

macos

ruby

I'm on MacVim 7.4 (I use the command line version), installed via Homebrew.

Vim is slow when syntax highlighting Ruby code. htop shows a 80%-100% CPU usage when moving inside a Ruby file in vim.

I found these here on SO:

  • Vim slow with ruby syntax highlighting
  • Syntax highlighting causes terrible lag in Vim

and tried the proposed solutions. What I did:

  • set regexpengine=1: nothing changed. Still very high CPU usage and slow performances.
  • set lazyredraw: things are better, but the tradeoff is very noticeable (cursor disappearing while moving)
  • I examined the autocmd statements in my .vimrc and found nothing slow in particular. I tried removing all the plugins but the problem is still there.

I tried turning the syntax off and, well, it solves the problem. Also, starting vim with vim -u NONE and then turning syntax on solves the problem, so it must be something in my .vimrc I guess?

Here's a link to my vimrc.

Edit

I may have found the guilty settings. It seems there are two settings that are noticeably slowing down movement in vim:

  • set relativenumber
  • set cursorline

Note that both of these settings trigger this behavior even alone.

These settings force vim to redraw quite a lot of stuff on the screen when scrolling holding j or k. I doubt there's a solution here, but I'm very open to anything to speed this up.

Edit #2

Note that relativenumber and cursorline trigger this behavior only when used in Ruby files. Every other filetype I tried (with relativenumber and cursorline on) scrolls smoothly, no matter how long.

like image 677
whatyouhide Avatar asked Apr 08 '14 22:04

whatyouhide


1 Answers

As avivr said, Vim is sometimes slow to (especially for ins-completion) in large files due to foldmethod=syntax

From :help todo:

  • Slow combination of folding and PHP syntax highlighting. Script to reproduce it. Caused by "syntax sync fromstart" in combination with patch 7.2.274. (Christian Brabandt, 2010 May 27) Generally, folding with 'foldmethod' set to "syntax" is slow. Do profiling to find out why.

The FastFold plugin makes it so folds are only recalculated on save (so you're always using foldmethod=manual -- but the folds are calculated with foldmethod=syntax or whatever you had set before).

This solved the problem for me. Now I can use compl-whole-line completion in my 5000 line C++ file and it's instant and snappy instead of taking minutes and unresponsive.

like image 163
idbrii Avatar answered Oct 21 '22 03:10

idbrii