Vim Slow with Ruby Syntax Highlighting

Vim slow with ruby syntax highlighting

The solution to this problem turned out to be the regex engine that vim uses.
The speculation on #vim on freenode is that the ruby syntax files use something that is slower on the new regex engine.

Any version older than and including Vim 7.3.969 has the old regex engine.
Add in set re=1 to your vimrc to force the old regex engine on any version newer (and don't forget to reload the file you're currently editing with :e).

Thanks to Houl, Dolio and dmedvinsky from #vim for help figuring it out.

I haven't had a chance to try the absolute latest version, there was a commit last night that may help with this issue. I will update this if I get the chance to try the bleeding edge version again.

do ruby plugins make starting vim very slow?

If you're using version 7.2.286 or newer, you can run vim --startuptime vim.out foo.rb to log how long the various parts of the startup process take.

Syntax highlighting causes terrible lag in Vim

You have autocmd spam. You should wrap all of your autocmd statements in groups which clear the group before re-adding the autocmds. It looks like your .vimrc has most autocmds commented-out, so maybe there is a plugin that is causing the issue. Check the output of this command:

:au CursorMoved

If there's a bunch of duplicate handlers there, that's your problem.

Here's an example of autocmd discipline from my .vimrc:

augroup vimrc_autocmd
autocmd!
"toggle quickfix window
autocmd BufReadPost quickfix map <buffer> <leader>qq :cclose<cr>|map <buffer> <c-p> <up>|map <buffer> <c-n> <down>

autocmd FileType unite call s:unite_settings()
" obliterate unite buffers (marks especially).
autocmd BufLeave \[unite\]* if "nofile" ==# &buftype | setlocal bufhidden=wipe | endif

" Jump to the last position when reopening a file
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

" ...etc...

augroup END

The autocmd! at the beginning of the augroup block clears out the current group (vimrc_autocmd, in this case) before re-adding the autocmds.

Ruby-like Syntax Highlighting in VIM for Thor


au BufRead,BufNewFile *.thor set filetype=ruby

I think should suffice... maybe this if you want to customize it later:

au BufRead,BufNewFile *.thor set filetype=thor
au! Syntax thor source $HOME/.vim/syntax/thor.vim

and copy ruby .vim syntax highlight file to $HOME/.vim/syntax/thor.vim

Disable specific Ruby regex pattern matching in Vim for performance

Put the following into a file ~/.vim/after/syntax/ruby.vim:

syntax clear rubySymbol

The after directory will ensure that this is called after the original $VIMRUNTIME/syntax/ruby.vim has been sourced, and the command removes the slow syntax definition.

Note that this may interfere with the operation of the syntax plugin; you may see wrong highlighting, and it may even completely mess up the parsing!

An alternative would be disabling syntax for the current file (:setlocal syntax=), or entirely (:syntax off).

Vim became very slow when process long string

Syntax highlighting is defined via regular expressions, and the matching can consume a lot of resources, especially on long lines and large buffers. You can turn off syntax for the problematic buffer with :setlocal syntax=, or disable it completely with :syntax off.

Recent Vim versions (7.4 with a "huge" build) also have a :syntime command that can show you which syntax rule is problematic, so that you may be able to disable only parts of the syntax highlighting.

Other settings can make working with large files slow. The LargeFile - Edit large files quickly plugin detects and disables those automatically for you.



Related Topics



Leave a reply



Submit