8

Im working on project that is in fact composed of several subproject, under a common git repository:

Project
   - Sub Project A
   - Sub Project B
   - ...

I never work on the main folder, and always start from one of the sub projects, the problem is no matter what I try CtrlP always does the search starting from the main folder where the repo is.

I've tried a few settings from the project repo but no matter, such as bellow, but still can't get it to make any effect.

let g:ctrlp_working_path_mode = 'ca'

Any tips please?

Dejan Skledar
  • 11,280
  • 7
  • 44
  • 70
Luis Martins
  • 1,421
  • 2
  • 18
  • 32

2 Answers2

8

Looking at the CtrlP docs suggests that you have three options:

  1. Disable CtrlP's working directory searching: let g:ctrlp_working_path_mode = ''. It will then only search under Vim's current working directory, so just :cd to one of your sub projects' directories.
  2. Ignore the sub project directories that you are not interested in: let g:ctrlp_custom_ignore = { 'dir': '\v[\/]Sub Project [AB]$' } (untested).
  3. Add Sub Project A, Sub Project B, etc. as root markers: let g:ctrlp_root_markers = ['Sub Project A', 'Sub Project B']. This should stop CtrlP from traversing up beyond those sub directories.

I would suggest the first option since the others are a bit too hacky for my taste. The last option also didn't work for me in a quick test.

Walter
  • 7,809
  • 1
  • 30
  • 30
  • Cool, I can now have search to be a bit more useful, just need to massage the ignore thing now. The first option was enough for I was looking after. Thanks. – Luis Martins Apr 02 '15 at 08:28
2

If you're used to CtrlP starting in your current working directory, and it suddenly seems to have stopped, it's probably a side effect of g:ctrlp_working_path_mode that is a bit unintuitive: it searches up the directory tree until it finds a source control root (like a .git folder), and treats that as the top level directory.

I'm used to it always being the top level of my current project, so when I started a new project, and it was using my home directory as the root, I was confused. It's because I hadn't yet initialized Git for the new project, so the first .git directory it found was in my home directory.

Initializing a Git repo for the new project made it behave as expected.

Here's the relevant section of the plugin help:

                                                'g:ctrlp_working_path_mode'

When starting up, CtrlP sets its local working directory according to this variable: let g:ctrlp_working_path_mode = 'ra'

c - the directory of the current file.
a - like "c", but only applies when the current working directory outside of
    CtrlP isn't a direct ancestor of the directory of the current file.
r - the nearest ancestor that contains one of these directories or files:
    .git .hg .svn .bzr _darcs
w - begin finding a root from the current working directory outside of CtrlP
    instead of from the directory of the current file (default). Only applies
    when "r" is also present.
0 or <empty> - disable this feature.

Note #1: if "a" or "c" is included with "r", use the behavior of "a" or "c" (as a fallback) when a root can't be found.

Note #2: you can use a b:var to set this option on a per buffer basis.

Jim Stewart
  • 16,964
  • 5
  • 69
  • 89