I try to delete some non-empty folder in netrw by pressing Shift d and, after press y, I got this error:

(netrw) unable to delete directory {path}

I already put this variable in my .config/nvim/init.vim file and doesn't works: let g:netrw_localrmdir='rm -r'

As I read, this variable only works with vim 7.4 and earlier.

Is there a way to delete non-empty directories with netrw in Vim 8+ or Neovim?

My setup:

OS: MacOs Catalina
NVIM v0.4.3


My intention is to use as few plugins as possible, but, netrw has some other bugs, so U gave up using netrw and installed NERDTree again.

2 Answers 2


There's a way to delete non-empty directories with netrw in vim 8+ or nvim?

You could do :!rm -rf directory

That warning means, you have files still in that directory. So if a file in that directory you want to delete is on the current buffer, you could do this.

:!rm -rf %:h

Which deletes the directory of the current file. %:h expands to the directory of the current file, and you can even press <tab> to have it expand and you can modify the path if you wanted.

Another alternative would be, use R and just move it to /tmp or something which gets deleted automatically by the system, in my case linux.

  • But /tmp only gets deleted on a shutdown, right? Or is it cleaned periodically ?
    – D. Ben Knoble
    Aug 2, 2020 at 3:00
  • I think it's on every restart. On WSL though, it never deletes /tmp so what I do is just add a script that deletes file older than 1week so something like this: fd . /tmp --changed-before 1w -H -x rm -rf. Which gets called every time I open my shell.
    – chriz
    Aug 2, 2020 at 5:57
  • Yeah macOS doesnt seem to delete either (except maybe restarts, tbh im not sure). Clever trick!
    – D. Ben Knoble
    Aug 2, 2020 at 12:23
  • @D.BenKnoble In Mac OS you can move it to ~/.Trash instead. Then there's an option where you can delete them every 30 days. If you want it sooner, then a script is better.
    – chriz
    Aug 8, 2020 at 5:15
  • How do I map any of these commands to the D command in netrw though (in Neovim or Vim > 7.4)?
    – Sasgorilla
    Mar 8, 2023 at 17:15

mf to mark the directory

mx to apply shell command to marked files

rm -rf <enter>
  • This is a great solution, thanks. Clean and extensible. May 21 at 21:03

Your Answer

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

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