NERDTree:在当前窗口打开文件?

NERDTree:在当前窗口打开文件?

当我在通过打开目录创建的 NERDTree 缓冲区中打开文件时,按下<CR>,它会在当前窗口中打开选定的文件除非该文件在另一个窗口中打开,在这种情况下,它会将光标移动到该窗口(如果需要,更改选项卡)。

有没有办法让 NERDTree 在 NERDTree 所在的缓冲区中打开文件?

(我本质上是想用 NERDTree 来替代 netrw。在这方面,NERDTree 的行为与 netrw 不同;我希望它在这里模仿 netrw。)

答案1

看来您正在寻找选项NERDTreeHijackNetrw,如NERDTree 文档

If set to 1, doing a
:edit <some directory>

will open up a "secondary" NERD tree instead of a netrw in the target window.
Secondary NERD trees behaves slightly different from a regular trees in the
following respects:
1. 'o' will open the selected file in the same window as the tree,
replacing it.
2. you can have as many secondary tree as you want in the same tab.

如果您正在寻找超出此范围的功能,您可以基于插件提供的 API 来实现它:

4. The NERD tree API *NERDTreeAPI*
The NERD tree script allows you to add custom key mappings and menu items via
a set of API calls. Any scripts that use this API should be placed in
~/.vim/nerdtree_plugin/ (*nix) or ~/vimfiles/nerdtree_plugin (windows).

The script exposes some prototype objects that can be used to manipulate the
tree and/or get information from it: 

g:NERDTreePath
g:NERDTreeDirNode
g:NERDTreeFileNode
g:NERDTreeBookmark

See the code/comments in NERD_tree.vim to find how to use these objects. The
following code conventions are used:
* class members start with a capital letter
* instance members start with a lower case letter
* private members start with an underscore

See this blog post for more details:
http://got-ravings.blogspot.com/2008/09/vim-pr0n-prototype-based-objects.html

一种可能的解决方案是创建一个映射,从光标下的文件中检索路径并使用它:edit

相关内容