Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy path file with NERDtree Vim plugin

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?

like image 772
Tárcio Zemel Avatar asked May 03 '13 23:05

Tárcio Zemel


3 Answers

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.

like image 60
Billy Chan Avatar answered Oct 18 '22 02:10

Billy Chan


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).

like image 30
Ingo Karkat Avatar answered Oct 18 '22 03:10

Ingo Karkat


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
like image 5
Peter Rincker Avatar answered Oct 18 '22 03:10

Peter Rincker