Vim scrolls very slowly when a line is too long

24

10

I would never have thought that Vim would be so slow. All I have is the following long line:

enter image description here
(Click image to enlarge)

I run Vim (MacVim) under Mac OS X with the terminal app. Here is my vimrc. I hope that it has nothing to do with some of my plugins. If I break up the big line in the image, everything is working fast again.

Matthias Guenther

Posted 2011-06-25T18:44:24.723

Reputation: 385

related: https://stackoverflow.com/questions/901313/editing-xml-files-with-long-lines-is-really-slow-in-vim-what-can-i-do-to-fix-th

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2019-12-19T13:42:44.710

+1. Thanks for the picture! That one line itself is extremely long. Remember that CLI text editors used to limit lines to 255 characters back in the days of DOS. Syntax highlighting requires that each HTML tag open and close be monitored, and each double quote as well, and then each variable. And I'm sure that each time you nest another tag inside the HREF tag, the editor has to figure out just what that means. I've seen emacs have issues highlighting text that VI has no problems with: You too can choose editors on-demand like we do with chrome, FF and the infamous IE browser. – Vlueboy – 2011-06-26T08:37:50.820

Answers

23

This is a known problem with Vim and very long lines. I see three solutions:

  1. Turn off syntax highlighting with :syntax off.
  2. Limit syntax highlighting with :set synmaxcol=200 or some other value.
  3. Break down your long line in smaller chunks with :s/\s<a/<C-v><Enter><a.

In this particular case I'd recommend solution 3.

romainl

Posted 2011-06-25T18:44:24.723

Reputation: 19 227

36

try following:

" Syntax coloring lines that are too long just slows down the world
set synmaxcol=128

else i recommend speeding up vim by:

set ttyfast " u got a fast terminal
set ttyscroll=3
set lazyredraw " to avoid scrolling problems

phux

Posted 2011-06-25T18:44:24.723

Reputation: 461

set synmaxcol=4096 completely resolved the issue of syntax highlighting being broken on long lines :) – Jay Taylor – 2016-09-18T15:43:23.213

2+1. This will be useful, even if it wasn't picked by the asker as "best" answer. – Vlueboy – 2011-06-26T08:28:48.700

2Wow synmaxcol made such a difference when writing blog posts in markdown. – Keith Smiley – 2013-08-09T18:00:27.333

lazyredraw did the trick for me. Even without any plugins scrolling through certain files was excruciatingly slow. This was the case in both vim and gvim. Profiling did not show anything. – Confusion – 2014-06-14T14:21:52.857

1

I think you seem to have cursorline set. I found that used to be the biggest contributor to lag in my vim. You might want to try disabling that.

AravindKrishnan

Posted 2011-06-25T18:44:24.723

Reputation: 11