When I try to insert the code below in vim using o in a Python file that contains a large dictionary on a single line, line 3 below, my terminal window hangs, and CPU usage spikes to 99%.
I have a Python test file that is similar to this:
1 from library import module
2
3 DICT = { <3000-6000 character dictionary on a single line> }
4 KEY = "examplekey"
5
6 def test_func_on_dict():
7 expected_output = 42
8 output = module.call_function(DICT, KEY)
9 assert output == expected_output
As I type o on line 5 the CPU spikes to 99% and I can't interact with the file. If I delete the large single-line dictionary the speed of vim goes back to normal.
As one of the biggest benefits of Vim is its speed of editing, this has started to grate on me pretty fast. I saw "How to find what slows down vim?" about profiling vim but my problem is on insert and not on the load time. I am using vim-plug.
My .vimrc looks like this:
call plug#begin('~/.vim/plugged')
Plug 'junegunn/seoul256.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'beautify-web/js-beautify'
Plug 'vimwiki/vimwiki'
call plug#end()
99.8 is the CPU % in htop:
It has been suggested my question should be closed because it is similar to "Why is pasting a long one-liner very slow in Vim's insert mode?". I don't think the suggest post answers my question because my long line, the large dictionary, is already present in the file. vim is not slow on paste. vim is slow on o insert below the long line. I think there is something to the issue being the time it takes to re-draw everything as noted in "Why is pasting a long one-liner very slow in Vim's insert mode?" but I do not see an obvious solution to the problem as of yet.
Spreading the dictionary out over many lines fixes the issue. Notably, when in :set paste
mode, there is no speed issue with the o insert command below the large dict on a single line. Also, whether in visual mode or paste mode, there is no issue when the cursor is above the large dict and o is pressed. However, I am also interested in why this happens, not just what the fix is.