20

The current working directory is ./A/B/. An empty document is opened when I type vim, and the netrw is opened with command :e. The window is split by vs., and I can navigate to the upper level directory, i.e., ./A/. Now I'd like to copy a file a_file.jpg from ./A/B/ to ./A/.

I tried yy on the target file and p in the target window (directory), but it did not achieve my goal.

Is there any way that can achieve the goal without installing extra plugins?

1
  • 1
    Try the following: hit mt on the target directory in which you want to make a copy of a file (to mark it ; the path to the folder should appear in the banner after Copy/Move Tgt:), hit mf on the file you want to copy to mark it as well, then hit mc to actually perform the copy.
    – saginaw
    Jan 26, 2016 at 7:38

3 Answers 3

27

You cannot use y, p etc., to copy files in netrw - it comes with its own commands. See :h netrw-mc:

MARKED FILES: COPYING                                           netrw-mc {{{2
            (See netrw-mf and netrw-mr for how to mark files)
                      (Uses the global marked file list)

Select a target directory with mt (netrw-mt).  Then change directory,
select file(s) (see netrw-mf), and press "mc".  The copy is done
from the current window (where one does the mf) to the target.

If one does not have a target directory set with netrw-mt, then netrw
will query you for a directory to copy to.

One may also copy directories and their contents (local only) to a target
directory.

Your case is simplified since ./A is the parent of ./A/B:

  1. Open ./A/B, move to the line having ../,
  2. Mark it with mt
  3. Move to the line with the file you want to copy.
  4. Press mf, and then mc.

Example:

$ tree foo
foo
└── bar
    └── test

1 directory, 1 file
$ vim foo/bar

Now:

  1. Move to .. and press mt:

    enter image description here

  2. The header will change to show the current target:

    enter image description here

  3. Move to the file (here test) and press mf. It gets highlighted for me:

    enter image description here

  4. Press mc - the highlighting goes away. Now navigate to the parent folder - the file should be present:

    enter image description here

11

I would do this from the command line mode:

  • Select the file you need in netrw
  • Open command the line and type - :!mv <C-R><C-F> ../<C-R><C-F>

Here <C-R><C-F> inserts file name under cursor, so you don't have to type the file name.

1
  • 1
    Very cool. Doesn't include the full path if you've traversed into your tree in netrw...
    – J0hnG4lt
    Mar 8, 2016 at 14:38
5
  • Set cursor on ./ (or directory in which you want to copy) , press mt
  • Set cursor on file you want copy, press mf, then mc, type a name of new file, enter
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.