I just copied a massive amount of text (on the order of millions of lines, I think) into a Vim register, opened a new file, pasted, and then proceeded to edit the new copy of the excerpt. Vim was reasonably quick throughout the whole process; it was a nice showcase of the power of Vim.
....except that I'm using the persistent undo feature. So after a little bit of time spent editing, I noticed that my Vim session was taking up an enormous amount of memory (about 3x as much as my Chrome session, which is a lot by Vim standards). At first I thought it was because my massive copy was still in one of the registers, but when I went to edit
.viminfo, the longest register value was about 20 lines. I tried restarting Vim a few times, but each time it loaded that particular file, it would hang for an unacceptable amount of time (again, by Vim standards).
...So I realized that I needed to delete my undo file for the problematic file. This solved my immediate problem, but I'd like to avoid encountering it again. So I would like an autocmd in my VimRC that will do the following:
- Upon loading a file, check the size of the corresponding undo file (if it exists)
- If the undo file is larger than
x Mb(or whatever size), do one of the following:
- Delete it
- Keeping only the most recent changes, delete changes until the file is a reasonable size (this would be the preferred behavior)
Any thoughts on how to do this?