10

For my repo, suppose it's called top

top\
  .gitignore
  foo\
  bar\

I want CtrlP to list files that are

  1. Under foo\
  2. Is not ignored by .gitignore defined in top\

If I cd into top\foo\, and open vim from there, 1 would be satisfied but not 2.
If I open vim on top\, 2 would be satisfied but not 1.

How do I achieve both 1 and 2?

I tried this gitignore vim script, but it only parses gitignore when I open vim in the root folder of a repo, so I can't do both 1 and 2 together.
Same for let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""', ag doesn't try to go up to the repo root and read gitignore from there.
Setting g:ctrlp_working_path_mode as r let CtrlP honors .gitignore in the top folder, but everything under top\ would be listed by CtrlP. I just want files in foo\.

Thanks.

octref
  • 6,521
  • 7
  • 28
  • 44
  • What about `CtrlP foo`? – romainl Nov 01 '14 at 21:26
  • @romainl This works but I'd have to type in :CtrlP foo everytime. If foo is deep below the project root then it's very hard to use. – octref Nov 02 '14 at 02:02
  • can't you modify the vim script to reccursively search for .gitgnore in parent directories ? – kamaradclimber Nov 02 '14 at 09:17
  • I set my CtrlP to use git ls-files as it's file lister. This ignores the `.gitignore` files but also looses untracked files. For untracked files I just use `git add` and they suddenly become tracked and CtrlP will pick them up. – Sukima Nov 03 '14 at 20:35

2 Answers2

12

From its home page it looks like you can use

let g:ctrlp_user_command = [
    \ '.git', 'cd %s && git ls-files . -co --exclude-standard',
    \ 'find %s -type f'
    \ ]

which will have the advantage of honoring all of git's ignore-pattern processing, not just the toplevel positive .gitiginore patterns.

jthill
  • 55,082
  • 5
  • 77
  • 137
2

Seems there is no apparent way to do it, so I just followed @kamaradclimber 's suggestion, spent an hour and made this: RootIgnore
Never coded in VimScript before so it took me some time :-)

You can install it using Vundle.
It searches upward recursively for .git dir, gets the .gitignore in the same dir as the .git dir, and sets wildignore accordingly.

Update:
@jthill's method works better than mine.
But CtrlP has custom search commands while CommandT does not. So my plugin can still be useful to CommandT users.

octref
  • 6,521
  • 7
  • 28
  • 44
  • I'm coming from the future. Apparently CommandT has [this functionality](https://github.com/wincent/command-t/blob/master/doc/command-t.txt#L764) built in by now. – m8mble Nov 15 '18 at 07:31