我还在学习像专业人士一样使用vim。在这个过程中我注意到当我在项目目录中的子模块中打开一个文件时,CtrlP插件会将搜索的根目录切换到子模块目录的根目录。有没有办法防止这种情况,并将根搜索目录保留为orignal项目或最初打开的项目之一?
答案 0 :(得分:8)
您可能想要调整g:ctrlp_working_path_mode
设置。听起来像你很可能想要一起禁用此功能,并使用:cd
手动设置工作目录。
来自GitHub上的当前ctrlp文档:
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.
答案 1 :(得分:3)
在.vimrc中,您必须通过设置:
来更改CtrlP行为let g:ctrlp_working_path_mode = 'rw'
使用此设置,它将在当前工作目录外部查找版本控制文件。
然后在处理项目之前,你将dir更改为主文件夹,其中main .git是或者内部的dir(不在子模块中):
:cd my/project/main/path
如果你在子模块中打开一个文件并且遇到C-p,如果当前工作的dir在子模块之外,它仍将使用你的主要.git文件。
答案 2 :(得分:1)
我在~/.vimrc
:
nnoremap <leader>f :CtrlP<CR>
nnoremap <leader>F :CtrlPCurWD<CR>
如果我想在项目中的任何地方打开文件,我会使用第一个文件,如果我想打开附近的文件,则使用第二个文件。