NerdTree copy command in Windows 7
Asked Answered
S

3

6

I don't see the menu option for Copy command. Here is the menu that I see on my Windows 7 machine:

NERDTree Menu. Use j/k/enter and the shortcuts indicated
==========================================================
> (a)dd a childnode
  (m)ove the curent node
  (d)elete the curent node

According to the plugin documentation, the Copy command is not supported on all platforms.

A textual filesystem menu is provided which allows you to create/delete/move file 
and directory nodes as well as copy (for supported OSs)

Has anybody managed to get this to work in Windows?

Syne answered 29/6, 2012 at 22:52 Comment(3)
Have you already tried to push c at that prompt?Oxytetracycline
Yes, pressing c has no effect.Syne
Apparently, others are facing the same issue but nobody seems to care. Also, see this post by NERDTree's author.Gavrilla
S
2

The root cause for the issue is discussed in detail(rather colorfully) in this blog post.(ht romainl). I managed to find a solution by using the cp.exe shipped with msygit.

Ensure cp.exe is in your path

The cp.exe file can be found in <GIT_HOME>\bin directory. My path didn't not contain the <GIT_HOME>\bin directory. So I copied cp.exe and msys-1.0.dll to a directory in my path.

Set the g:NERDTreeCopyCmd variable

Add the line below to the end of the _vimrc file

let g:NERDTreeCopyCmd= 'cp -r '

Fix the implementation of s:Path.copy function.

Replace the lines 2297-2299 of ~/vimfiles/bundle/nerdtree/plugin/NERD_tree.vim (assuming you used pathogen for managing vim plugins)

  • Replace the lines 2297-2299

      let dest = s:Path.WinToUnixPath(a:dest)
    
      let cmd = g:NERDTreeCopyCmd . " " . escape(self.str(), s:escape_chars) . " " . escape(dest, s:escape_chars)
    
  • With the lines below

      let dest = a:dest
      let cmd = 0
      if s:running_windows
          let cmd = g:NERDTreeCopyCmd . '"' . self.str() . '" "' . dest . '"'
      else
          let cmd = g:NERDTreeCopyCmd . " " . escape(self.str(), s:escape_chars) . " " . escape(dest, s:escape_chars)
      endif
    
Syne answered 30/6, 2012 at 23:40 Comment(1)
This tip doesn't work anymore as is. You have to edit vimfiles/bundle/nerdtree/lib/nerdtree/path.vim, around line 166. And use "nerdtree#runningWindows()" instead of "s:running_windows"Vichy
C
2

I got it working by installing Gow

choco install -y gow

Then adding this line to vim

let g:NERDTreeCopyCmd= 'cp -r'

Thanks: https://github.com/scrooloose/nerdtree/issues/152

PS: The choco command comes from https://chocolatey.org/

Colligate answered 22/4, 2016 at 14:59 Comment(1)
It works! However, I get the error NERDTree: Could not copy node when the file I'm trying to copy has spaces in it... Any advice about this?Bingo
P
0

What I did was I added the following to my vimrc

if (has('win32'))
    " let g:NERDTreeCopyCmd= 'copy '
    let g:NERDTreeCopyCmd= 'Copy-Item -Recurse '
endif

First one works, but I set it to the second, I think you need that for copying directories properly..

I just tried delete, and that also fails. Guess we need a similar workaround.

EDIT: Sorry, you will have to set your shell to run PowerShell for the second command to work!

Pt answered 10/3, 2022 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.