Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: insert mode is very slow with 400+ lines

Tags:

vim

line

I have a file with 400+ lines (it's a thesis). When I edit it somewhere near the top (say, on line 20), Vim is snappy as always. However, editing it near the bottom (around line 400) causes a noticeable delay between me typing the character and Vim showing it on the screen. As a consequence, it is almost impossible to edit a file this big.

What is the reason for this and what can I do?

I've tried toggling the swapfile, syntax, scrolloff etc, but it doesn't seem to help. The maximum number of lines for Vim should be 2147483647, so I should actually have a long way to go here :)

In case this is related to setting maxmem, then what would be a reasonable value, considering that I edit files up to 2500 lines?

Thanks very much for any help! Cheers.

like image 400
martz Avatar asked Feb 26 '13 10:02

martz


3 Answers

In my case relative numbers with same file opened in multiple windows was lagging. I had to do either :set norelativenumber or close another windows.

like image 162
synthetic64 Avatar answered Nov 16 '22 02:11

synthetic64


I recently came across this exact problem - lag while typing at the bottom of a relatively short (markdown) file. After uninstalling plugins and commenting out most of the settings in my .vimrc, I discovered that the issue was markdown folding coming from the vim-markdown plugin that is pre-installed with vim. Commenting out let g:markdown_folding = 1 did the trick.

I still wanted to have automatic folding on markdown files, so I installed vim-markdown-folding and there are no issues with performance.

like image 34
kdwarn Avatar answered Nov 16 '22 03:11

kdwarn


Okay, folding was the problem here (I had some bad settings for foldlevelstart). So, based on my experiences and these issues:

set foldenable              " can slow Vim down with some plugins
set foldlevelstart=99       " can slow Vim down with some plugins
set foldmethod=syntax       " can slow Vim down with some plugins

Other things to check/toggle are syntax, filetype, wrap and line length (some plugins can be slow with very long lines).

Running Vim without your current settings is a good starting point. Thanks to @Frederik for pointing me to this:

vim -u NONE

After this, disabling all plugins is a good start. See also for general knowledge: :help slow

like image 28
martz Avatar answered Nov 16 '22 03:11

martz