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

How can I manually set ctrlp's directory to search on a per project basis?

Open AlexAllocated opened this issue 12 years ago • 8 comments

At work I have a "work-code" folder in my home directory. Within that directory there are about five git repositories that are all related. I love how ctrlp travels the directory tree until it finds a .git folder to use as reference. However, in this case I want ctrlp to jump up one directory to "work-code" and search all five of my repositories.

I know that can disable ctrlp's feature to traverse the directory tree looking for .git but I don't want to disable it. I just want to manually specify the ctrlp directory but only in those five projects. Is there a way to tell ctrlp what base directory to use on a per project basis?

AlexAllocated avatar Feb 12 '14 23:02 AlexAllocated

It would be cool if I could do something simple like drop a .ctrlp file in a project's directory with some simple config stuff in it, like the root directory to use. If that was an option then I could put a .ctrlp file in ~/work-code/project1/.ctrlp and inside that file manually set the root directory to ~/work-code/.

AlexAllocated avatar Feb 13 '14 00:02 AlexAllocated

If you set let g:ctrlp_working_path_mode = 0 it will use the directory you started vim in to search out of. So what I do is just start vim from my root directory with vim ., and then use ctrlp to open the file(s) I want to edit.

positron avatar Feb 13 '14 03:02 positron

Interesting. Not quite the ideal solution I was hoping for but I appreciate the reply :)

I've just gone ahead with this for now:

noremap <C-a> :CtrlP ~/work-code/<CR>

So I can do ctrl-a when I want to search all my work code.

I just think it would be so cool to be able to drop .ctrlp files in any directory and add it to list of files/folders to look for when it's traversing up the directory tree. If it finds the file and it's empty then it just uses it as a root marker like it already does. However, if it finds settings inside then it should apply those settings. One of those settings being something like

let g:ctrlp_root_directory = "../"

In my setup this would tell ctrlp to go up one more directory (to my work-code directory).

AlexAllocated avatar Feb 13 '14 03:02 AlexAllocated

You'll probably have more freedom using a local .vimrc for the project, and put the settings there. If you don't want to do that, a simple mapping to :CtrlP ../ should be suffice, I think.

kien avatar Feb 15 '14 06:02 kien

It would be really good if you could add directories to scan like you do with tags, ie set ctrlp_search_dir+=~/work/blah ... I was looking to see if this was possible with the current code, but I cannot find any options for this. Could this be a new feature that is need?

othane avatar Jun 13 '16 21:06 othane

Could a variable be set with some other mapping which can then be used with let g:ctrlp_root_directory = PROJECT_ROOT? I don't know Vimscript ;_;

domi91c avatar Jan 30 '17 23:01 domi91c

Sweet, this works: let g:ctrlp_root_markers = ['.ctrlp']

https://coderwall.com/p/5xv7sq/ctrlp-root-markers

domi91c avatar Jan 30 '17 23:01 domi91c

Are root markers and custom CtrlP mapping the only way to solve this still? I've got a tree that looks something like

FolderRoot
  \--> CodePWD (where my pwd is)
  \--> FolderIWantToAdd (folder I want ctrlp to include)
  \--> UnwantedFolder1 (one of dozens of folders I want to continue to ignore)
  \--> SecondUnwantedFolder (one of dozens of folders I want to continue to ignore)
  \--> Unwanted3rdFolder (one of dozens of folders I want to continue to ignore)

I can add a root_marker inside of FolderRoot, but that'll include UnwantedFolder1/2/3 as well. My current solution is to map :CtrlP and :CtrlP ../FolderIWantToAdd, but it would be nice if I could have both in one search.

tankorsmash avatar Nov 11 '18 00:11 tankorsmash