Vim takes an annoyingly noticeable long time to insert a newline (o
in normal mode or return key in insert mode) when inserted at the end of a specific code block that could be considered complex.
How would I go about identifying the cause and fixing the problem?
Case-specific information:
I my case, a problematic Python code block is the following, which contains multiple single quotes in double-quoted strings:
for item in tree.xpath("//li"):
a = item.xpath(".//div[contains(concat(' ', normalize-space(@class), ' '), ' alpha ')]/text()")[0]
b = item.xpath(".//div[contains(concat(' ', normalize-space(@class), ' '), ' betahaus ')]/text()")[0]
c = item.xpath(".//div[contains(concat(' ', normalize-space(@class), ' '), ' capitalism ')]/text()")[0]
d = item.xpath(".//div[contains(concat(' ', normalize-space(@class), ' '), ' doughnuts-of-the-realm ')]/a")[0].attrib['href']
g = item.xpath(".//span[contains(concat(' ', normalize-space(@type), ' '), ' dontcare ')]/text()")[0]
h = item.xpath(".//span[contains(concat(' ', normalize-space(@type), ' '), ' foo ')]/text()")
The delay is less than a second but noticeable.
The machine is a AMD Phenom(tm) 9550 2.2GHz, 64bit Quad-Core Processor and this is on Arch Linux with .vimrc moved (so Arch's vim defaults are used). Both vim and gvim are affected.
If I copy paste the lines defining variables 5 times, resulting in about 48 lines, the delay is 3 seconds long. Increasing to over 400 lines causes the same delay which makes me assume there's a timeout that is being reached.
A video showing the issue: https://youtu.be/rCSfSASrZjQ