ctrlp.vim icon indicating copy to clipboard operation
ctrlp.vim copied to clipboard

Symlinked directory/files doesn't appear in search

Open ahmedelgabri opened this issue 12 years ago • 6 comments

I have a project that has a symlinked directory but the symlinked directory & files doesn't appear in the search.

The project structure looks like this

root
   |- src
    ├── folder 
       └── folder2 -> symlinked to (another-root/src)

another-root
   |- src -> symlink source

and here is my CtrlP settings

" CtrlP settings
let g:ctrlp_match_window = 'top,order:ttb'
let g:ctrlp_user_command = 'ag %s -l --hidden -g ""'
let g:ctrlp_use_caching = 0
let g:ctrlp_jump_to_buffer = 'Et'
let g:ctrlp_open_new_file = 't'
let g:ctrlp_open_multiple_files = 't'
let g:ctrlp_follow_symlinks = 2

ahmedelgabri avatar Jun 09 '14 21:06 ahmedelgabri

@adkazakov Wow! I guess someone didn't read the issue properly. Maybe this will help you https://github.com/kien/ctrlp.vim/blob/master/doc/ctrlp.txt#L409-L416, instead of just being rude like this & then deleting your reply without even an apology.

You maybe forgot that people get notified through emails & you can't delete these emails.

screen shot 2014-07-30 at 12 24 00 pm

ahmedelgabri avatar Jul 30 '14 08:07 ahmedelgabri

@ahmedelgabri Man, sorry - it's comments not for you! It's my fail ))))

justcrafter avatar Jul 30 '14 09:07 justcrafter

@adkazakov Ok, that's fine.

ahmedelgabri avatar Jul 30 '14 09:07 ahmedelgabri

@ahmedelgabri I'm having the same issue. This does not appear to be a problem when running ag from the command line, but when running it through ctrlp it just fails to include symlinks. This is what I use for my .vimrc:

if executable('ag')
    let g:ctrlp_user_command = 'ag --ignore-case --nogroup --hidden --follow
        \ -l -m 50000
        \ --ignore .git
        \ --ignore .svn
        \ --ignore .hg
        \ --ignore .DS_Store
        \ %s -g ""'
endif

Notice the --follow flag? That tells ag to follow symlinks as well. However, this option does not work within ctrlp; the shortened -f option does not work either.

The only way I've gotten ctrlp to actually follow symlinks is by using either of these three flags (reference https://www.mankier.com/1/ag):

  • -a or --all-types
  • -t or --all-text
  • -u or --unrestricted

The problem with including those is that they end up ignoring any custom ignore patterns and other ignore files, such as .gitignore, .hgignore, or .agignore, which means ag searches through .git/ directories and all other ones like it. This obviously slows things down and produces cluttered search results. If you're okay with that, include one of those three flags and you'll get symlinks followed in searches.

danemacmillan avatar Feb 15 '15 23:02 danemacmillan

After playing with the configuration some more, I've settled on a workaround / solution to this problem. ag makes use of a .agignore file, which can be specified explicitly, or fallback to a user's home directory. This has the added benefit that even when running ag from the command line, and not just through ctrlp, that the ignores specified are already defined.

The key flags to use are -U (Ignore VCS ignore files [.gitignore, .hgignore, svn:ignore], but still use .agignore) and -p (Provide a path to a specific .agignore file). The -p flag is not necessary if an .agignore file exists in the home directory, but I've included it to be explicit.

This is my new config for .vimrc related to ctrlp:

if executable('ag')
    let g:ctrlp_user_command = 'ag --ignore-case --nogroup --hidden --follow
        \ -U -p ~/.agignore
        \ -l -m 50000
        \ %s -g ""'
endif

Now when running ctrlp from vim, symlinks are suggested / followed in search results.

Read https://www.mankier.com/1/ag for additional flags.

danemacmillan avatar Feb 16 '15 01:02 danemacmillan

It seems cntrlp doesnt follow symlinks for me as well. I did set the follow_symlinks flag, but it didnt change anything. https://github.com/kien/ctrlp.vim/blob/master/doc/ctrlp.txt#L409-L416

Is there a solution to this?

alphaCTzo7G avatar Mar 31 '18 14:03 alphaCTzo7G