For some reason, when I insert a newline in vim (either with the o key, or an enter), it takes quite a bit of time for vim to actually insert the new line. This problem is exacerbated when I press and hold the enter key - in this case, vim totally freezes, and takes about 3-4 seconds to render all of the new lines. This problem seems to be specific to Python files, as I have tested this behavior with other large non-python files, and do not see this problem.
Some of the slowdown is caused by the vim-polyglot language pack, but disabling that plugin only helped the slowdown a little bit, not eliminate it completely.
Opening a file with vim -u NORC
also didn't help much at all, and the only way I was able to finally get smooth inserting of newlines is with vim -u NONE
or syntax off
, leading me to believe that this is a syntax highlighting problem.
Here's the syntime report for just holding down the enter key for a couple of seconds (with -u NORC
:
TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN
0.467286 11548 0 0.000109 0.000040 pythonMatrixMultiply ^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*
0.404281 12396 968 0.000109 0.000033 pythonNumber \%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>
0.376318 11548 0 0.000085 0.000033 pythonString [uU]\=\z('''\|"""\)
0.340580 11548 0 0.000222 0.000029 pythonMatrixMultiply \%(\w\|[])]\)\s*@
0.263625 14333 5095 0.000063 0.000018 pythonString [uU]\=\z(['"]\)
0.250727 11548 0 0.000058 0.000022 pythonRawString [uU]\=[rR]\z('''\|"""\)
0.241550 11548 0 0.000061 0.000021 pythonRawString [uU]\=[rR]\z(['"]\)
0.229741 21954 13645 0.000047 0.000010 pythonNumber \<\%([1-9]\d*\|0\)[Ll]\=\>
0.228875 11548 0 0.000392 0.000020 pythonNumber \<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=
0.202706 11548 0 0.000050 0.000018 pythonMatrixMultiply [^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@
0.175705 11548 0 0.000040 0.000015 pythonNumber \<\d\+[eE][+-]\=\d\+[jJ]\=\>
0.171692 11548 0 0.000047 0.000015 pythonNumber \<\d\+[jJ]\>
0.059275 24104 16355 0.000032 0.000002 pythonAttribute \.\h\w*
0.047092 11660 2977 0.000035 0.000004 pythonComment #.*$
0.021249 4826 4826 0.000020 0.000004 pythonString \z1
0.008962 11548 0 0.000015 0.000001 pythonNumber \<0[xX]\x\+[Ll]\=\>
0.008958 11548 0 0.000015 0.000001 pythonNumber \<0[oO]\=\o\+[Ll]\=\>
0.008755 11548 0 0.000004 0.000001 pythonNumber \<0[bB][01]\+[Ll]\=\>
0.004358 11548 952 0.000016 0.000000 pythonEscape \\$
0.003670 11484 0 0.000017 0.000000 pythonDecoratorName @\s*\h\%(\w\|\.\)*
0.001265 4760 0 0.000001 0.000000 pythonEscape \\N{\a\+\%(\s\a\+\)*}
0.001153 4826 0 0.000001 0.000000 pythonString \\\\\|\\\z1
0.001129 4760 0 0.000001 0.000000 pythonEscape \%(\\u\x\{4}\|\\U\x\{8}\)
0.001116 4760 0 0.000001 0.000000 pythonEscape \\[abfnrtv'"\\]
0.001098 4760 0 0.000001 0.000000 pythonEscape \\\o\{1,3}
0.001072 4760 0 0.000001 0.000000 pythonEscape \\x\x\{2}
0.000749 3104 0 0.000001 0.000000 pythonDecorator @
0.000700 3119 0 0.000001 0.000000 pythonDoctestValue ^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\+
0.000601 3119 0 0.000010 0.000000 pythonDoctest ^\s*>>>\s
0.000068 62 0 0.000007 0.000001 pythonSync ^\%(def\|class\)\s\+\h\w*\s*[(:]
3.524359 288911
I'm not entirely sure why there is so many regexes being matched, as the only thing I'm doing is inserting new lines. Furthermore, most of these regexes, such as pythonMatrixMultiply, aren't even matching anything. Any help would be appreciated. For reference, here is my vim and neovim versions (I mostly use neovim, but this problem happens in vim as well).
NVIM v0.3.1
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 07 2019 11:40:34)