4

I use set matchpairs+=<:> in my config (to help when editing HTML, for instance), but I just noticed it made vim very slow when editing emails.

Is there a way to have this setting without paying a performance penalty? (e.g., automatically disabling it in cases like emails when it's obviously not relevant to see the numerous > as delimiters)

5

If your emails have a particular file type, you could use BufRead or BufNewFile or FileType to turn off some matchpairs automatically:

au BufRead,BufNewFile *.email set mps-=<:>
  • 1
    OK, but that's just a workaround, it means vim may also be slow on other file types, or on emails that aren't correctly detected. I'm surprised that there doesn't seem to be a generic way to fix this? Thanks, in any case! – a3nm Oct 16 '15 at 8:15
  • 2
    I would suggest exactly the opposite: only set mps when editing HTML instead of making it the default. – Vitor Oct 16 '15 at 10:06
5

The slowness of delimiter matching is not caused by vim itself but by the matchparen plugin, which is part of the vim distribution and loaded by default in /etc/vim/vimrc in Debian. (This is why I still had the problem without a vimrc.)

Fortunately the matchparen plugin supports a timeout when looking for matches, so the slowness can be avoided by setting those timeout to lower values. I added the following to my vimrc:

let g:matchparen_timeout = 2
let g:matchparen_insert_timeout = 2

2 milliseconds is plenty of time on modern machines to find a relevant delimiter, and when scrolling down in this file on my machine, display is no longer slugging and CPU usage for vim stays at 15% or so.

Edit: actually I increased it to 20, otherwise I sometimes see it fail. This means there is still some sluggishness, but it's better than without the setting.

1

I guess it has something to do with your .vimrc somewhere else, I can still edit emails as long as 10000 lines without having any slowdown with

set matchpairs+=<:>

Can you try with an empty vimrc and start finding out by commenting out other things ?

  • The problem also occurs with just that setting. Using the trivial .vimrc paste.fulltxt.net/sov8ji, when I try opening paste.fulltxt.net/urbFS7i and scroll down by holding 'j', it gets sluggish essentially immediately. (Can you reproduce this? I have "VIM - Vi IMproved 7.4", "2:7.4.826-1" from Debian amd64.) So I still claim this isn't any interaction with my other settings. – a3nm Oct 16 '15 at 20:16
  • By the way, the problem is not specific to < and >, just opening with paste.fulltxt.net/7BxA with syntax on and trying to scroll should be enough to bring vim to its knees. I would be puzzled if there's nothing that can be done for that... – a3nm Oct 16 '15 at 20:18

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.