1

I'm still learning to use vim like a pro. In the process I have noticed that when I open up a file in submodule in a project directory CtrlP plugin switches the root for search to the root of the submodule directory. Is there a way to prevent this and keep the root search directory the one of the orignal project or the the one that was opened up initially?

3 Answers 3

8

You probably want to tweak the g:ctrlp_working_path_mode setting. It sounds to me like you most likely want to just disable this feature all together and manually set your working directory with :cd.

From the current ctrlp docs on GitHub:

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.
3

In your .vimrc you must change CtrlP behavior by setting:

let g:ctrlp_working_path_mode = 'rw'

With this setting it will look for version control files in current working dir outside.

Then before working on your project you change dir to its main folder, where main .git is or to a dir inside that (not in a submodule):

:cd my/project/main/path

If you open a file inside a submodule and while there hit C-p, if current working dir is outside the submodule, it will still use the file were your main .git is.

1

I've got these mappings in my ~/.vimrc:

nnoremap <leader>f :CtrlP<CR>
nnoremap <leader>F :CtrlPCurWD<CR>

I use the first if I want to open a file anywhere in my project and the second if I want to open a nearby file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.