greek0.net/vim: indent/html.vim can cause short hangs
Description
On an HTML file I was editing I noticed that backspacing was very slow (taking about half a second for one backspace). First I thought it was because of the spell checker, but the bug still happened without any loaded scripts, and with disabled syntax highlighting.
The bug was triggered by one HTML file, where I had a long line (~450 chars), that wrapped several times. On the next line backspacing got really slow, and by holding backspace for 2 seconds I could lock up vim for more then 10 seconds. Vim deleted only 38 characters within this time.
I've done several tests to see what could be the cause of this problem. It doesn't seem to be connected with the wrapping of the long lines, since making my xterm so wide that the line fit on one screen line without wrapping didn't help. The time of the lock-up seems to be roughly proportional to the square of the number of characters in the line directly above (see below). Inserting a single line between the long line, and the line where I'm backspacing immediately eliminates the problem.
Affected versions, system details
I've been able to trigger the bug with vim 6.1 as well as with 6.3 (with the latest version available from Debian Unstable: 6.3-025+1). For more details view my bugreport.txt file. Some people on #vim @ Freenode have also been able to confirm the bug: kisielk, fs111 (vim7 CVS)
Steps to reproduce
- Save that HTML file to your disk: triggerbug1.html
- Start vim, activate the filetype based indentation.
- Open the file in vim, goto line 27, column 115 (just after "vario").
- Press i, then hold backspace for about 2 seconds.
- Vim then locks up for about 10 seconds on my machine.
The expected behavior would of course be that vim just deletes the characters, without locking up and eating all available CPU resources.
Cause of the bug
I've tracked down the problem to the HTML indenting plugin.
`filetype indent off
`, closing and reopening the file
fixes the problem. A quick-fix is to remove
<bs>
from indentkeys
.
I don't really know if it is possible to really fix the the underlying
problem, namely that HtmlIndentGet
is quite slow.
Further research showed that the cause of the slowness are the two
functions HtmlIndentOpen
and HtmlIndentClose
.
The functionality of these functions seem pretty basic, but I don't
know how to change them to perform better.