1

我喜欢 NERDTree 和 Command-T。所以我想对当前项目使用 Command-T 搜索文件。(我使用 NERDTree 书签作为项目)。因为 Command-T 用于:CommandT <path>主动搜索,默认<path>是 pwd。我想将<path>当前文件自己的 NERDTree 书签路径更改为当前文件。

像这样:

我有一个名为的书签TestProject,路径是~/testproject.

现在,我正在写文件是~/testproject/class/test.php,如果使用:CommandT,我会得到搜索目录是~/testproject/class/。但我想搜索全局项目(~/test/project),我不想输入:CommandT ~/testproject/

4

2 回答 2

0

完全无视 NERDTree,您可以将 CommandT 映射配置为默认包含您的项目根目录。为了使其灵活,您可以从环境变量动态加载每个 vim 会话的项目根目录:

"If the $H environment variable is available, assume it contains CommandT's root dir
if !empty($H)
  nnoremap <silent> <Leader>t :CommandT $H<CR>
else
  nnoremap <silent> <Leader>t :CommandT<CR>
endif

或者更简单地说,您可以使用 $PWD,它应该反映您开始vim会话的目录。

关于您提出的解决方案,您确实可以cd在 NERDTree 中将光标放在您想要 cd 到的节点上,然后按cd(请参阅参考资料:h NERDTree-cd)。这会更改缓冲区的:pwd/输出,如果您在缓冲区中开始:!pwd,将使用新值进行搜索。问题是,将尝试在您最近访问的编辑缓冲区中打开您选择的文件,这不会受到缓冲区中的ing 的影响。现在,由于版本 1.3.1尝试使用相对路径(相对于from the )打开选择,它很可能无法正常工作。NERDTreeCommandTNERDTreeCommandTCommandTcdNERDTreeCommandT:pwdNERDTree buffer

下面是一个git-format用于 CommandT v1.3.1 的 ted 补丁,以使其工作:

From cf4569af2f5d06673d96ac0f798c22612b5579f5 Mon Sep 17 00:00:00 2001
From: Petr Skocik <pskocik@gmail.com>
Date: Fri, 1 Aug 2014 02:10:35 +0200
Subject: [PATCH] open selection by its absolute rather than relative path

---
 ruby/command-t/controller.rb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ruby/command-t/controller.rb b/ruby/command-t/controller.rb
index 6026aca..4774345 100644
--- a/ruby/command-t/controller.rb
+++ b/ruby/command-t/controller.rb
@@ -240,6 +240,7 @@ module CommandT
       selection = File.expand_path selection, @path
       selection = relative_path_under_working_directory selection
       selection = sanitize_path_string selection
+      selection = VIM::pwd + '/' + selection
       ensure_appropriate_window_selection
       ::VIM::command "silent #{command} #{selection}"
     end
-- 
1.9.1
于 2014-08-01T00:16:55.540 回答
0

Command-T 的“下一个”分支(还没有发布版本),特别是这个提交:

https://github.com/wincent/Command-T/commit/ebcda3ce2e90211345eab89fd972e22b75883440

添加从当前编辑的文件或 Vim 的 PWD(可配置)锚定搜索到最近的 SCM 目录的选项。这可能会解决这个用例。

于 2014-08-01T00:53:30.490 回答