Vim huge delay when inserting newline after complex strings
<p>Vim takes an annoyingly noticeable long time to insert a newline (<code>o</code> in normal mode or return key in insert mode) when inserted at the end of a specific code block that could be considered complex.</p>

<p>How would I go about identifying the cause and fixing the problem?</p>

<h1>Case-specific information:</h1>

<p>I my case, a problematic Python code block is the following, which contains multiple single quotes in double-quoted strings:</p>

<pre><code>  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()")
</code></pre>

<p>The delay is less than a second but noticeable.</p>

<p>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.</p>

<p>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.</p>

<p>A video showing the issue: <a href="https://youtu.be/rCSfSASrZjQ" rel="nofollow">https://youtu.be/rCSfSASrZjQ</a></p>

<p>It's likely related to syntax highlighting; check whether the delay is gone after <code>:syntax off</code>.</p>

<p>If your Vim version (recent ones with "huge" features) supports the <code>:syntime</code> command, you can dive deeper; cp. <code>:help :syntime</code>.</p>

<p>This may turn up a pattern that is responsible for the slowness; you'd then contact the syntax plugin author (whose address / link to issue tracker you'll find in the script's header: <code>$VIMRUNTIME/syntax/python.vim</code>.</p>

python vim archlinux