以下面的例子为例:
img http://dl.dropboxusercontent.com/u/62862049/Screenshots/j6.png
如何创建将执行rm contas.ls
的映射?
答案 0 :(得分:2)
NERDTree有一个菜单系统。在Nerdtree缓冲区中按m
,您将看到菜单。
所以你可以创建一个映射:
map <buffer> ,d mdy
删除所选文件。这实际上会触发菜单。
如果你想在不触发菜单的情况下静默删除文件,你可以:
map <buffer> ,d :call g:NERDTreeFileNode.GetSelected().delete()|call NERDTreeRender()<cr>
您可能希望将映射放在autocmd中,以便它只影响nerdtree缓冲区。
答案 1 :(得分:2)
:h NERDTreeKeymapAPI
4.1. Key map API *NERDTreeKeymapAPI*
NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
Adds a new keymapping for all NERD tree buffers.
{options} must be a dictionary, and must contain the following keys:
"key" - the trigger key for the new mapping
"callback" - the function the new mapping will be bound to
"quickhelpText" - the text that will appear in the quickhelp (see
|NERDTree-?|)
Additionally, a "scope" argument may be supplied. This constrains the
mapping so that it is only activated if the cursor is on a certain object.
That object is then passed into the handling method. Possible values are:
"FileNode" - a file node
"DirNode" - a directory node
"Node" - a file or directory node
"Bookmark" - A bookmark
"all" - the keymap is not constrained to any scope (default). When
thei is used, the handling function is not passed any arguments.
Example: >
call NERDTreeAddKeyMap({
\ 'key': 'foo',
\ 'callback': 'NERDTreeCDHandler',
\ 'quickhelpText': 'echo full path of current node' })
\ 'scope': 'DirNode'
function! NERDTreeCDHandler(dirnode)
call a:dirnode.changeToDir()
endfunction
<
This code should sit in a file like ~/.vim/nerdtree_plugin/mymapping.vim.
It adds a (redundant) mapping on 'foo' which changes vim's CWD to that of
the current dir node. Note this mapping will only fire when the cursor is
on a directory node.
帮助文档示例代码中有一些拼写错误('echo full path ...',当它没有时,关闭尽早调用一行),但这是一个有效的例子:
call NERDTreeAddKeyMap({
\ 'key': '<F3>',
\ 'callback': 'NERDTreeExample',
\ 'quickhelpText': 'echo full path of current node',
\ 'scope': 'FileNode' })
function! NERDTreeExample(filenode)
echo a:filenode.path._strForGlob()
endfunction
NERDTree中有很多函数。您可以将上面的函数更改为此以探索一下:
function! NERDTreeExample(filenode)
echo keys(a:filenode)
endfunction
前面的例子使用path._strForGlob
,我发现这是使用这个,一旦我认为“路径”可能是候选人(那里有很多其他的):
function! NERDTreeExample(filenode)
echo keys(a:filenode.path)
endfunction
阅读文档。它们告诉你在哪里保存东西等等。你也可以浏览它附带的脚本文件。它全部设置在折叠中,在折叠时很容易扫描。
答案 2 :(得分:1)
对于最简单的情况,例如你问题中的情况,你可以这样做:
:!rm filename " works with tab completion
或
:!rm <C-r><C-f> " inserts the filename under the cursor
NERDTree提供内置Netrw功能的一小部分,其中一个不在于该子集的是用于删除文件或目录的D
映射。在安装NERDTree之前,您是否尝试过netrw(:EX
,:Vex
,:Sex
,:h netrw
)?