Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling syntax and syntax folding in vim with large C file makes completion slow

Tags:

c

vim

When I have syntax on in a large C file (about 8000) lines the completion ctrl-p and ctrl-n are very slow (more than 20). When I turn syntax off then completion takes less than a second.

I figured out a minimal way of reproducing this behaviour. Use an empty .vim folder and create a .vimrc with only these lines:

set syntax on
set foldmethod=syntax

When you open a large C file, completion (and even general editing) becomes very slow.

Edit:

This behavior was due to the fact that I was using a beta version. I am not sure if I should delete this question altogether, or leave it so if others have the same problem can have some clue about it.

like image 763
skeept Avatar asked May 26 '10 21:05

skeept


1 Answers

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 182
idbrii Avatar answered Sep 29 '22 00:09

idbrii