Ignore custom directories in ctrlp.vim

2.7k Views Asked by At

I want to ignore dist, .git directories for ctrlp.vim. And my .vimrc configure is below:

let g:ctrlp_custom_ignore = {
  \ 'dir': '\v[\/](\.git|dist)$'
}

I have two questions:

  • It does not ignore the dist directory.
  • What is the \v mean in the statement?

PS: This is my ctrlp configure of .vimrc

""" ctrlp
   let g:ctrlp_use_caching = 1
   let g:ctrlp_clear_cache_on_exit = 0
   let g:ctrlp_cache_dir = '$HOME/.vim/cache/ctrlp'
   let g:ctrlp_max_files = 1000
   let g:ctrlp_max_history = &history
   let g:ctrlp_max_depth = 10
   let g:ctrlp_user_command = [
         \ '.git', 'cd %s && git ls-files . -co --exclude-standard',
         \ 'rg %s --files --color=never --glob ""',
         \ 'find %s -type f'
         \ ]
   let g:ctrlp_custom_ignore = {
     \ 'dir': '\v[\/](\.git\|dist)$',
     \ 'file': '\v\.(exe|so|dll)$',
   \ }
   "let g:ctrlp_custom_ignore = 'dist'
   " let g:ctrlp_user_command = ['rg --files']
   let g:ctrlp_working_path_mode = 'ra'
   let g:ctrlp_reuse_window = 'startify'
map ff :CtrlP<cr>
3

There are 3 best solutions below

0
On

Vim's regexes are unfortunately not like any other systems, making them cumbersome and painful to work with. I'm not sure if CtrlP's ignore supports \v, I wouldn't add it here. I would also remove the leading slash. Try this (and restarting Vim):

let g:ctrlp_custom_ignore = {
    \ 'dir': '\.git\|dist$'
\ }

The \v is the "very magic" switch, which you should always use for searching in Vim (again, unsure if CtrlP supports it), to make them more usable:

nnoremap / /\v

It makes special characters like + behave like normal regex characters, instead of poorly defined Vim regex characters.

0
On

Answer 1:

Please add following line in your .vimrc

let g:ctrlp_custom_ignore = 'dist'

I placed this line at last position in .vimrc


Answer 2:

\v search for "one vertical whitespace character: line feed, carriage return, vertical tab, form feed, paragraph or line separator".

For details visit rexegg.

0
On

if you use g:ctrlp_user_command, g:ctrlp_custom_ignore then will not work. rg can ignore files too, just put them into .gitignore, rg will ignore any files and directories in .gitignore.