Is there some way to copy the path of a file in the Vim's NERDtree plugin?

Better: is there some plugin to make the same operations the SideBarEnhancements plugin of Sublime Text does?

有帮助吗?

解决方案

NERD_tree comes with its own extension system; just put the following fragment into ~/.vim/nerdtree_plugin/yank_mapping.vim:

call NERDTreeAddKeyMap({
        \ 'key': 'yy',
        \ 'callback': 'NERDTreeYankCurrentNode',
        \ 'quickhelpText': 'put full path of current node into the default register' })

function! NERDTreeYankCurrentNode()
    let n = g:NERDTreeFileNode.GetSelected()
    if n != {}
        call setreg('"', n.path.str())
    endif
endfunction

Of course, you can adapt the default key (yy), and register ("; use + for the clipboard).

其他提示

This is what I found for NERDTree with a quick google: CopyPath

However it sounds like you are trying to make vim into Sublime Text. Vim tends to have a very different philosophy on text editing than most text editors. In my personal opinion it is often better to work with vim than against it. Here is a nice post by Drew Neil of Vimcasts explaining the benefit to split explorers.

Probably the more vim way of inserting a path is to use file completion. When in insert mode you can trigger this completion by pressing <c-x><c-f> then go through the menu with <c-p> and <c-n> (previous and next respectively). If you want to insert the current buffers path you can paste it via the % register e.g."%p or in insert/command-line mode press with <c-r>%.

For more help see:

:h ins_completion
:h i_CTRL-R
:h quote%
:h registers

I guess what you really need is a context menu like that sublime plugin?

That's built-in with NERDTree.

Just hit m on the node you highlighted and you'll see a new window pop under asking you what you want to do. The basic functions are: Add, Delete, Move, Copy.

There is also a plugin to let you search(using grep), either for single file or whole directory highlighted.

NERDTree also provides API for your easily built any custom actions in that context window.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top