Copying files with Vim's netrw on Mac OS X is broken
Asked Answered
P

3

13

To copy a file in Vim using netrw has the following steps:

  1. Select the destination directory (using mt)
  2. Select the file to be copied (using mf)
  3. Proceed with copying (using mc)

The commands to use in netrw are:

mt run while cursor is on top of the directory intended to be the destination
mf run while cursor is on top of the file intended to be copied
mc run while cursor is on top of the destination ("marked target") directory

If I do this on an example project, Vim will display something like:

Copy foo.md to : bar.md

Suggesting it's about to do what I want it to, but upon confirming this I get the following error:

1 **error** (netrw) tried using g:netrw_localcopycmd<cp>; it doesn't work!

I've read online that netrw is considered pretty buggy and so there doesn't appear to be much documentation or notes on how to resolve this issue.

I should be clear and state that I'm not interested in using NERDTree.

Pioneer answered 4/8, 2015 at 13:57 Comment(0)
P
2

I think I've figured out the initial issue:

I had two folders foo and bar (one file in each) and I marked foo as the target directory and then pressed ENTER on the bar folder (just to have a look at the files inside it), and then pressed ENTER on foo (to also have a look at the files inside it). At this point I was then moving my cursor up inside the bar folder and pressed mf on the file I wanted to copy. But as far as netrw was concerned, I was still "focused" on the foo folder.

The solution seemed to be:

At this point (imagining I had taken the above steps until just before pressing mf): I should press ENTER on the bar folder (hiding the listed files) and then press ENTER on the bar folder again (now re-showing the content/listed files) and finally press mf on the file inside bar that I want to copy. NOW as far as netrw is concerned, I've marked the file inside the correct directory and the mc command will succeed.

The mistake I had made was assuming that just moving the cursor inside a folder was enough for mf to work. I neglected to realise that I had to be "focused" in the correct folder for the mf command to work.

Pioneer answered 9/8, 2015 at 20:36 Comment(0)
B
14

read more at :help netrw-cd to understand more about current directory and browsing directory mismatch.

you either want to press cd before the process or just let g:netrw_keepdir=0 in your .vimrc

(the mapping used to be c, then it changed to cd)

Balk answered 20/12, 2016 at 7:8 Comment(5)
These don't work either in neovim os x, just fyi :-|Diggins
@Diggins Just tried and it works. To be more explicit, I mted the . (current) directory, then mfed the file I want to copy, then cmc and voilà.Baptism
@adrien it does not work for me also :/Mealtime
@JoeCabezas I'll need more details than that. Have you created a question?Baptism
The cmc solution didn't work for me in Neovim 0.8 (nightly), but setting netrw_keepdir to 0 did the trick.Silsbye
P
2

I think I've figured out the initial issue:

I had two folders foo and bar (one file in each) and I marked foo as the target directory and then pressed ENTER on the bar folder (just to have a look at the files inside it), and then pressed ENTER on foo (to also have a look at the files inside it). At this point I was then moving my cursor up inside the bar folder and pressed mf on the file I wanted to copy. But as far as netrw was concerned, I was still "focused" on the foo folder.

The solution seemed to be:

At this point (imagining I had taken the above steps until just before pressing mf): I should press ENTER on the bar folder (hiding the listed files) and then press ENTER on the bar folder again (now re-showing the content/listed files) and finally press mf on the file inside bar that I want to copy. NOW as far as netrw is concerned, I've marked the file inside the correct directory and the mc command will succeed.

The mistake I had made was assuming that just moving the cursor inside a folder was enough for mf to work. I neglected to realise that I had to be "focused" in the correct folder for the mf command to work.

Pioneer answered 9/8, 2015 at 20:36 Comment(0)
S
0

Had to make a fixing mini-plugin for this. It can be either installed as plugin or copy-pasted to local config.

It wraps netrw to preserve current dir thus fixing mc and mm commands (on any OS, not Mac only), with netrw_keepdir=1 enabled.

https://github.com/dzirtusss/netrw_keepdir_fix

Sedimentation answered 27/8, 2024 at 17:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.