How to debug when vim becomes quite slow?

209 views
Skip to first unread message

kindle4ever

unread,
Feb 18, 2012, 9:15:00 AM2/18/12
to vim...@googlegroups.com
When i open a file with 4000line code, the response of vim becomes quit slow. At the mean time i input a word, vim costs 40% cpu. After switching to another vimrc, it works fine again. 
Can anyone tell me how to debug in vim? Because the vimrc script is written by me and i can't locate the error after checking for a long time.
Thanks in advance.

Tim Chase

unread,
Feb 18, 2012, 9:31:08 AM2/18/12
to vim...@googlegroups.com, kindle4ever

I'd start by investigating the following:

- do you have some large register-value stored in your .viminfo?
(would slow startup, but shouldn't slow use once you've started)

- exceptionally long lines with certain syntax files (you'd see
the symptoms on certain file-types but not others; you mention 4k
lines, but not the max line-length or file-size)

- mappings that are waiting for pending keystrokes to discern
them from each other (check if changing 'timeoutlen' alters
performance)

- some particular search (whether a stored pattern in your
default search register, or a :match command) that is highly
inefficient (control+C might help if you're stuck in a delay;
clearing the various search/:match settings should improve this)

- you might have some CursorHold or CursorHoldI event that is
doing time-consuming things

- you might be something at high frequencies (check the values of
'updatecount' and 'updatetime')

- you might be writing to an exceptionally slow device
(swap-files, backup files, etc; written to a floppy or a network
drive with high latency or a hard-drive that is about to die)


You can always bisect your vimrc to track down the offending
line(s). Including your vimrc might also help folks track down
any issues.

-tim


Marc Weber

unread,
Feb 18, 2012, 9:35:41 AM2/18/12
to vim_use
Excerpts from kindle4ever's message of Sat Feb 18 15:15:00 +0100 2012:

> When i open a file with 4000line code, the response of vim becomes quit
> slow. At the mean time i input a word, vim costs 40% cpu. After switching
> to another vimrc, it works fine again.
wild guess:
- switch of syntax : syn off
- switch off folding: set fdm=manual

get ideas from "LargeFile" plugin on www.vim.org

You already have a working and a bad .vimrc?

but first of all: Learn how to track down errors. You do so by
a) finding a case which works
b) compraing the case which does not by the one which does step by step.

in your case I'd start with empty .vimrc. If it does goto the middle of
your .vimrc and add a "finish".
bad? continue putting the first half into two pieces by adding finish
good? remove "finish" and put the second half of the .vimrc into pieces.

Vim ignores everything after "finish"

This technic is called bisecting.

Then you'll find the cause fast.

If you find that line causing the trouble is "plugin on" then move
plugin/*.vim files somewhere else (temporarely) or use vim-addon-manager
which is particularly good at starting vim with different plugin
combinations easily.

Marc Weber

lith

unread,
Feb 19, 2012, 10:09:26 AM2/19/12
to vim...@googlegroups.com
Am Samstag, 18. Februar 2012 15:15:00 UTC+1 schrieb kindle4ever:
When i open a file with 4000line code, the response of vim becomes quit slow. At the mean time i input a word, vim costs 40% cpu. After switching to another vimrc, it works fine again.

Does this happen only with specific filetypes? In my experience, a badly programmed foldexpr function can slow down things considerably if it causes vim to frequently rescan the whole file.

Regards,
Tom

kindle4ever

unread,
Feb 20, 2012, 10:51:51 PM2/20/12
to vim...@googlegroups.com
After syn off, vim is speed up. 
Reply all
Reply to author
Forward
0 new messages