简体   繁体   English

使用NERD树时,使用VCSCommand插件提交目录

[英]Commiting directories with VCSCommand plugin when also using NERD Tree

I am using vim 7.3, the NERDTree 4.1 plugin and VCSCommand version 1.99.42. 我使用的是vim 7.3,NERDTree 4.1插件和VCSCommand版本1.99.42。

To commit a directory in VCSCommand you need have the directory buffer open (it's the same with all commands on directories), however whenever I try to open a directory buffer with the NERD Tree plugin installed it refers to the buffer as Nerd_tree_* and not the directory name which I need to make a relevant commit. 要在VCSCommand中提交目录,您需要打开目录缓冲区(它与目录上的所有命令相同),但每当我尝试打开安装了NERD Tree插件的目录缓冲区时,它将缓冲区称为Nerd_tree_ *而不是我需要进行相关提交的目录名。

How do I prevent this from happening? 我该如何防止这种情况发生? How do I open a standard directory buffer with NERD tree installed? 如何打开安装了NERD树的标准目录缓冲区? How do I turn NERD Tree off periodically to perform the command? 如何定期关闭NERD树以执行命令?

Note: I am aware of this stackoverflow question where the dev says he disabled the NERD Tree plugin because he was using Command-T as a file explorer, but I would like to continue to use NERD Tree, there is no mention of disabling NERD Tree in the help. 注意:我知道这个stackoverflow问题 ,dev说他禁用了NERD Tree插件,因为他使用Command-T作为文件浏览器,但是我想继续使用NERD Tree,没有提到禁用NERD Tree在帮助中。

There is a solution but it required some coding. 有一个解决方案,但它需要一些编码。

You need to update netrw and NERDTree plugins with kind of enable/disable interface. 您需要使用启用/禁用接口更新netrwNERDTree插件。

I create this gist for you with two files that have to be changed. 我用两个必须更改的文件为你创建这个要点 The files itself are also attached. 文件本身也是附加的。

  • netrwPlugin.vim resides in vim installation directory under. netrwPlugin.vim位于vim安装目录下。
  • NERD_tree shall be in your ~/.vim/plugin directory (unless you use pathogen ). NERD_tree应位于〜/ .vim / plugin目录中(除非您使用病原体 )。

With this change you can use 通过此更改,您可以使用

call DisableNERDTree()

to disable NERD and make vim use netrw (it's original file manage) and 禁用NERD并使vim使用netrw(它的原始文件管理)和

call HijackNERTW()

To restore NERDTree again. 要再次恢复NERDTree。

Of course you alsoneed do call the functions before and after related VCS command either by using your own wrapper functions or modifying VCS itself. 当然,您也可以通过使用自己的包装函数或修改VCS本身来调用相关VCS命令之前和之后的函数。

Hope this helped. 希望这有帮助。

Edit 2011-03-17: 编辑2011-03-17:

Calling those functions manually works well. 手动调用这些功能效果很好。 Ie: 即:

  1. you call call DisableNERDTree() 你打电话call DisableNERDTree()
  2. then you edit the folder 然后你编辑文件夹
  3. then you use VCS command 然后你使用VCS命令
  4. and finally call HijackNERTW() 最后call HijackNERTW()

I updated the patch so those functions could be used in automated way. 我更新了补丁,以便可以自动使用这些功能。 DisableNERDTree() now changes directory to the one opened. DisableNERDTree()现在将目录更改为打开的目录。 Eg: 例如:

fun! NewVCSadd()
   call DisableNERDTree()
   :e . "start netrw
   :VCSAdd<CR>
   call HijackNERTW()
   :e . "start NERDTree
endfunction

I use a simple combination: When I'm planning for recursive Diff or recursive Commit - I run command :Hexplore, which opens netrw in split-window, navigate to necessary directory and run :VCSCommit or :VCSDiff. 我使用一个简单的组合:当我计划递归Diff或递归提交时 - 我运行命令:Hexplore,它在拆分窗口中打开netrw,导航到必要的目录并运行:VCSCommit或:VCSDiff。 That's a simple fix without additional changes or complex manipulations :). 这是一个简单的修复,没有额外的更改或复杂的操作:)。

Devemouse changes and function example allowed me to construct the following 2 wrapper functions, which perform VCS command and then returns vim to it's previous state Devemouse更改和函数示例允许我构造以下2个包装函数,它们执行VCS命令然后将vim返回到它之前的状态

" ------------------ Functions ------------------------------

" Wrapper function for VCSAdd to enable it to work with Nerd tree
fun! NewVCSAdd()
   call DisableNERDTree()
   edit . "start netrw
   execute 'VCSAdd'
   call HijackNERTW()
   quit " quit add windows 
   quit " quit out of netrw-NerdTree window (we want it pure)
   NERDTree . 
endfunction

" Wrapper function for VCSCommit to enable it to work with Nerd tree
fun! NewVCSCommit(comment)
   call DisableNERDTree()
   edit . "start netrw
   execute 'VCSCommit ' . a:comment
   call HijackNERTW()
   quit " quit commit windows 
   quit " quit out of netrw-NerdTree window (we want it pure)
   NERDTree .
endfunction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM