165

I have come across the awesome ctrlp.vim plugin. It is a good alternative to the Command-T plugin which I have used before. What I did not like about Command-T is that it would take about 20-30 seconds to rescan files when it is invoked for the first time after starting vim.

CtrlP works a lot faster but it does not seem to automatically rescan for newly created files. How should I trigger a rescan manually?

Thanks!

Lucas Wilson-Richter
  • 2,274
  • 1
  • 18
  • 24
ko1Rn
  • 1,847
  • 2
  • 12
  • 9

5 Answers5

299

From the documentation:

<F5>
  - Refresh the match window and purge the cache for the current directory.
  - Remove deleted files from MRU list.

This assumes you're in ctrl-p mode already. Note that you can hit F5 in the middle of a query, i.e., you can type a few characters, find it's not matching a recently updated file, and hit F5 to refresh right then. It will automatically show you the match if the file was just added to the ctrl-p cache.

mahemoff
  • 44,526
  • 36
  • 160
  • 222
Jeet
  • 38,594
  • 7
  • 49
  • 56
66

As Jeet says you can press F5 but if that doesn't work you can always run :CtrlPClearCache which is what F5 is supposed to run.

From the documentation

:CtrlPClearCache
Flush the cache for the current working directory. The same as pressing <F5> inside CtrlP.
To enable or disable caching, use the |g:ctrlp_use_caching| option.

user229044
  • 232,980
  • 40
  • 330
  • 338
Oskar Persson
  • 6,605
  • 15
  • 63
  • 124
11

I added this to .vimrc which turns off ctrlp caching

g:ctrlp_use_caching = 0

Pip
  • 1,062
  • 8
  • 6
  • This is probably the best and most accurate answer to the original question. Especially if you are on a computer (I'm looking at you Apple..) where the function row needs an alternate modifier key to access. – Devon Kiss May 31 '19 at 05:15
  • i like this answer, even with out cache, ctrp is fast enough already, can use Ag to boost up the speed – Nhan Tran Jun 04 '20 at 06:01
6

If you want, you can automatically bust the cache when a save happens, so it will be forced to refresh on next use.

Put this in your vimrc (credit docwhat):

" CtrlP auto cache clearing.
" ----------------------------------------------------------------------------
function! SetupCtrlP()
  if exists("g:loaded_ctrlp") && g:loaded_ctrlp
    augroup CtrlPExtension
      autocmd!
      autocmd FocusGained  * CtrlPClearCache
      autocmd BufWritePost * CtrlPClearCache
    augroup END
  endif
endfunction
if has("autocmd")
  autocmd VimEnter * :call SetupCtrlP()
endif

Unfortunately there's no way to automatically keep the cache fresh in the background.

mahemoff
  • 44,526
  • 36
  • 160
  • 222
3

I know this is a old question, but it's so simple that I have to comment. Put this in your .vimrc

:nnoremap <c-p> :CtrlPClearCache<bar>CtrlP<cr>

This will refresh the cache and then call CtrlP. No more missing files.

Luiz Rocha
  • 41
  • 3