Dear the community,
I am running gVim74 on a Windows machine and I have CtrlP.vim installed through Vundle.
Every time I start a new session of gVime and press Ctrl+P, it would take more than 15 seconds to initialize. I resorted to solutions in Issue #395, but nothing changed after I had specified the following in my _vimrc.
Any one could help me with this slow-boot issue?
All the best,
You may need to use double backslashes, or use forward slashes, in your cache dir path.
Thanks for pointing the format for the cache dir path, however, it does not solve the problem. Here is some further observations:
Through the following, the directory had been written on after my pressing of
The odd thing is: in the aforementioned directory, CtrlP will create a .txt file named as "C%%WINDOWS%system32.txt", which is the name of the working directory of my Vim.
I tried to use cd commend (in my _vimrc) after the line specifying the ctrlp_cache_dir, however, a new .txt file will be created in the 'C:~\CtrlP' directory.
Up to this point, I hope it would be clear what the problem would be coming from.
Thanks for your help!
What if you try something like this in your vimrc:
let g:ctrlp_cache_dir = expand("<sfile>h") . '/ctrlp_cache'
It should make CtrlP cache stuff just next to your vimrc in a ctrlp_cache folder. This is more or less what I have and it works on Windows...
So, I did as suggested but it made the things worse. After I commented out my previous specification for ctrlp_cache_dir and used the line suggested above, CtrlP would have to reinitialize again every time I escape to normal mode.
To be more precise, when I change my directory to my dropbox folder and press , it would take up to 10 seconds to initialize. If I were using the previous setting (let g:ctrlp_cache_dir='C:\Users\Linfeng\Documents\Vim-document\CtrlP'), I will not have to wait for another 10 seconds if I escape to normal mode and then press . However, under the new specification, I would wait for the same 10 seconds after escaping to normal mode and press . This time, I would have to reinitialize within the same gVim session.
Any idea why this keeps occurring?
Wait, what do you have on Dropbox? Your code, or the CtrlP cache? The CtrlP code is a bit hard to read for me, but I can see it's doing some timestamp comparisons to figure out if it should re-index a directory... maybe Dropbox is somehow changing timestamps a bit too much? Try to not use Dropbox to see if that fixes it.
Other than that, yeah I've got no idea :( I suppose you don't have any let g:ctrlp_use_caching = 0 left somewhere? (check that it's still at 1 or undefined). Also check the permissions are OK on the cache folder.
let g:ctrlp_use_caching = 0
So, what should be stored in the CtrlP cache directory? I have two directories, both containing a file called "cache.txt", and a temp-file named in a wired way (documenting the files in the CWD of Vim, when pressing Ctrl+P). And the temp file will be deleted after closing the gVim session.
I found that in the two sub-directories, the "cache.txt" files will not get deleted. The will be appended to in stead. However, the temp file (e.g. C%%Image.txt), will be deleted after the ending of the session.
I think this is where the re-initializing problem comes from. Is there a way to prevent Vim from deleting this file? I have tried to make a copy of the temp file and paste it back to the cache directory. And this would save the effort of re-initialization.
In the cache folder you should get 2 directories, hist and mru... one is the history of your searches, I think, and the other is the list of "most recently used" files. So they persist across Vim sessions (if you close Vim and re-open it, you can press <Tab> and quickly open the last files you were working on last time).
In the same cache folder, you'll also see those weirdly named files (they look like paths with % characters instead of slashes). Those list the files in a given directory, so that pressing <C-p> several times will only scan that directory once (the first time). But it's cleaned by default when exiting Vim, presumably because there's a chance things will change before next time Vim starts... so next time you use Vim, it will rescan again each directory in which you use CtrlP. If you don't want this, set g:ctrlp_clear_cache_on_exit to 0. Then you should see those weird files persist in the cache directory, and CtrlP won't rescan anything until you press <F5>.
Great! This is a perfect heal!
So I added the following line to my _vimrc and it worked.
let g:ctrlp_clear_cache_on_exit = 0
Lastly, note that is used to refresh the cache while one is in CtrlP console (correct me if I used the wrong name). That is, and then press will force a refresh of the cache.
Thanks a lot!
@llinfeng fixed same issue for me, ty