From 12dea6ccb2381a2b6b8ae0bf17b4078699bbfec3 Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Thu, 13 Jun 2019 09:17:19 -0400 Subject: [PATCH] Add a "copy path to clipboard" menu option (#1002) * Add menu item to copy the node's path to the clipboard. It works on Mac. Check Windows later. * Handle case where clipboard is not a compiled feature of Vim. * Change menu text if clipboard is unavailable. --- nerdtree_plugin/fs_menu.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index 3eef517..5c37e4d 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -37,6 +37,7 @@ endif if g:NERDTreePath.CopyingSupported() call NERDTreeAddMenuItem({'text': '(c)opy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'}) endif +call NERDTreeAddMenuItem({'text': (has("clipboard")?'copy (p)ath to clipboard':'print (p)ath to screen'), 'shortcut': 'p', 'callback': 'NERDTreeCopyPath'}) if has("unix") || has("osx") call NERDTreeAddMenuItem({'text': '(l)ist the current node', 'shortcut': 'l', 'callback': 'NERDTreeListNode'}) @@ -364,6 +365,17 @@ function! NERDTreeCopyNode() redraw! endfunction +" FUNCTION: NERDTreeCopyPath() {{{1 +function! NERDTreeCopyPath() + let l:nodePath = g:NERDTreeFileNode.GetSelected().path.str() + if has("clipboard") + let @* = l:nodePath + call nerdtree#echo("The path [" . l:nodePath . "] was copied to your clipboard.") + else + call nerdtree#echo("The full path is: " . l:nodePath) + endif +endfunction + " FUNCTION: NERDTreeQuickLook() {{{1 function! NERDTreeQuickLook() let treenode = g:NERDTreeFileNode.GetSelected()