4

Using the CtrlP plugin, I'm typing .. several times to get to the root directory of a project, then perform the search from there.

However after I reopen CtrlP it still searches in the directory of the current file.

How can I get it to stick to the directory that I originaly set ?

mihai
  • 37,072
  • 9
  • 60
  • 86

1 Answers1

6

By reading its documentation, of course.

  • If you want CtrlP to always open in your project's root directory, if applicable, just add this line to your ~/.vimrc:

    let g:ctrlp_working_path_mode=2
    
  • But you could also use both :CtrlP to browse in the current directory and :CtrlpRoot to browse in the root of your project.

  • Or simply use :CtrlPLastMode to launch CtrlP in… the last mode.

  • If your project doesn't fit CtrlP's definition of a project, a simple mapping could be enough:

    nnoremap <key> :CtrlP /path/to/project<cr>
    

    or you could use this option:

    let g:ctrlp_root_markers = ['']
    

edit

My answer was based on the version of CtrlP currently installed on my machine.

The latest version adds an optional argument to :CtrlPLastMode: --dir which does exactly what you are looking for:

:CtrlPLastMode --dir

The g:ctrlp_working_path_mode values are different, too. I believe r is the equivalent of 2.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 1
    k, but none of these suggestions seem to be the answer. I don't see the option '2' in the docs, the available options for `g:ctrlp_working_path_mode` seem to be `c, a, r, w or 0`. Also CtrlP seems to identify a project by some dir that has a `.git` file inside. I just want it to stick to the last dir I searched in. If this stuff is not possible I'll just take it as an answer. – mihai Nov 08 '12 at 15:30
  • got it. `:CtrlPLastMode --dir` does the job – mihai Nov 08 '12 at 18:44
  • actually it seems like opening another file changes the working dir...so that option is pretty much useless. Guess the solution is to just touch a `.git` file in the project dir. – mihai Nov 08 '12 at 21:10