Search code examples
vimdirectorytargetunsetnetrw

unset target directory after copying a file in vim netrw


It is well known that vim's netrw extension allows one to manage files directly inside vim. For example to copy a file using the following key strokes in vim:

mf (to mark each file)
mt (to set the current directory as the target)
mc (to copy the marked files into the target)

However, after all of that is done, the target directory is still set in the netrw headers at the top:

"   Copy/Move Tgt: /home/...

I want to unset the target directory because I don't want to accidentally copy other marked files to the previously targeted directory. I would rather netrw prompt me after my intentions are complete.

However, I can't seem to find this answer anywhere online.

How can I unset the target directory?


Solution

  • In the vim :help docs it states:

      * Also, if the cursor is in the banner, then the netrw window's 
        currently displayed directory is used for the copy/move-to target.
        Unless the target already is the current directory.  In which case,
        typing "mf" clears the target.
    

    However, this is not true. Typing mf will only mark or unmark files if your cursor is on that file.

    I did, however, find through trial and error that if you place your cursor in the banner (the commented section at the top of netrw), and then type mt twice, this actually does clear the target directory.

    So:

    Place cursor anywhere in the banner, and type:

    mtmt
    

    The target directory inside the banner will disappear.