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

Can't get CtrlP to set working dir as root folder

我正在处理的项目实际上由几个子项目组成,在一个公共 git 存储库下:

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

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

我已经尝试了项目仓库中的一些设置,但不管怎样,例如下面的设置,但仍然无法发挥任何作用。

let g:ctrlp_working_path_mode = 'ca'

有什么建议吗?

查看 CtrlP docs 表明您有三个选择:

  1. 禁用 CtrlP 的工作目录搜索:let g:ctrlp_working_path_mode = ''。然后它将仅在 Vim 的当前工作目录下搜索,因此只需 :cd 到您的子项目目录之一。
  2. 忽略您不感兴趣的子项目目录:let g:ctrlp_custom_ignore = { 'dir': '\v[\/]Sub Project [AB]$' } (未测试).
  3. 添加子项目A子项目B等作为根标记:let g:ctrlp_root_markers = ['Sub Project A', 'Sub Project B']。这应该会阻止 CtrlP 向上遍历这些子目录。

我会建议第一个选项,因为其他选项对我来说有点太老套了。最后一个选项在快速测试中对我也不起作用。

如果您习惯于从当前工作目录开始使用 CtrlP,而它突然似乎停止了,这可能是 g:ctrlp_working_path_mode 的副作用,有点不直观:它向上搜索目录树直到找到源代码管理根目录(如 .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.