无法使CtrlP将工作目录设置为根文件夹

8

我正在处理一个由多个子项目组成的项目,它们都在同一个 Git 代码库中:

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

我从不在主文件夹上工作,总是从其中一个子项目开始,问题是无论我尝试什么,CtrlP始终从存储库所在的主文件夹开始搜索。

我已经尝试了一些项目存储库中的设置,如下所示,但仍然无法使其产生任何效果。

let g:ctrlp_working_path_mode = 'ca'

请问有什么提示吗?

2个回答

8
查看CtrlP文档,有三个选项可供选择:
  1. 禁用CtrlP的工作目录搜索:let g:ctrlp_working_path_mode = ''。然后它只会在Vim的当前工作目录中搜索,所以只需要:cd到你的子项目目录之一。
  2. 忽略你不感兴趣的子项目目录:let g:ctrlp_custom_ignore = { 'dir': '\v[\/]Sub Project [AB]$' }未经测试)。
  3. Sub Project ASub Project B等添加为根标记:let g:ctrlp_root_markers = ['Sub Project A','Sub Project B']。这应该阻止CtrlP超越这些子目录。
我建议选择第一种选项,因为其他选项对我来说有点过于hacky。最后一种选项在我的快速测试中也没有起作用。

很酷,现在我可以让搜索功能更有用了,只需要调整一下忽略的东西。 第一个选项已经足够满足我的需求了。谢谢。 - Luis Martins

2
如果你习惯于CtrlP在你当前的工作目录中启动,但突然间它似乎停止了,那很可能是的一个副作用,这有点不直观:它会沿着目录树向上搜索,直到找到一个源代码控制根目录(比如.git文件夹),并将其视为顶层目录。
我习惯于它始终是当前项目的顶层目录,所以当我开始一个新项目时,它把我的家目录作为根目录,我感到困惑。这是因为我还没有为新项目初始化Git,所以它找到的第一个.git目录在我的家目录中。
为新项目初始化Git仓库后,它就表现得像预期的那样。
以下是插件帮助文档的相关部分:
                                                '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.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接