2

I had a very large (14 digit) decimal number in my (Windows) clipboard. I had vim open in normal mode on the command line at the time. Accidentally, I pressed some key/mouse combination that caused vim to repeat a write command many times. vim was not responding for a while (I'm assuming it started a huge disk write). I killed vim. After opening the file, I saw that it was appending some text (in vim's clipboard) to my file over and over again (I should have executed something like 23280664932781p).

After deleting these lines and the swap file (I deleted the swap file because vim was complaining about it whenever I open the file), I found that the undo file had become very large (~700MB). Now, as soon as I launch vim, it does a lot disk reads and is slowing down everything else. I appears to hog my CPU and memory too (CPU usage was constantly above 25%, disk was upto 85% and memory was above 90%). I can't use anything else for some time as it reserves a large buffer in memory. Exiting vim has also become very slow.

I'm still new to vim, and I don't know how to safely lower the size of the undo file (I don't want to forget the entire undo history because of this one thing). I opened the .un~ file to see what's wrong, it looked like this,

undo file contents

It occurs to me that each line in this file maintains one command (or old content) in the past history (because scrolling past this line took a very long (CPU) time). I don't know if vim is logging the actual content or just the command.

Please explain what has happened and how to fix this.

size of undo file

1

You should simply remove that undo file, it's unlikely you'll manage to get something useful from it.

You can actually trim the undo history by setting 'undolevels' (see also :help clear-undo), but when you do so, the newer changes are preserved and the older ones are purged. If the newer changes are the problematic ones, trimming them means trimming the older entries you presumably would like to be able to access.

(In the unlikelyhood that you're interested in the changes that come after the problematic one, trimming it by setting 'undolevels' might actually work.)

In order for you to get to the undo actions that precede the large one, you'll need to get past that one (two times actually, since I imagine there's one action and the undo of that action.) Going through them again is likely to make Vim allocate a lot of memory, start using swap, get your machine thrashing.

Vim undo files are per file that you edit, so dropping this particular undo file will only lose your undo history for that particular file, not any other file for which you are saving persistent undo history.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.