Skip to content

Instantly share code, notes, and snippets.

@KevinSjoberg KevinSjoberg/gist:5068370
Last active Jul 27, 2017

What would you like to do?
Removing non-empty local directories with netrw

A few months ago I read Drew Neil's article about split windows and the project drawer. It's a great article and I strongly recommend you to go ahead and read it.

The article got me spending some time with netrw and sure enough, it replaced NERDTree. One thing that annoyed me though, was its default for deleting directories. Quoting from :help netrw-delete.

Deleting/removing files and directories involves moving the cursor to the file/directory to be deleted and pressing "D". Directories must be empty first before they can be successfully removed.

This is not a default I'm happy with, but as with everything else in Vim, netrw is customisable. The default command for deleting local directories is rmdir which requires the directory to be empty. By setting g:netrw_localrmdir to something else, such as rm -r I get the behavior I want.

Excerpt from my .vimrc:

" Allow netrw to remove non-empty local directories
let g:netrw_localrmdir='rm -r'

Happy Hacking!

GitHub: KevinSjoberg | Twitter: KevinSjoberg


This comment has been minimized.

Copy link

ming-codes commented Dec 26, 2013

Thanks for the tip!

With this, you're free to change the rm command to anything you want. Right now I disabled the rm command on my machine with alias and switched to use trash instead to move everything to trash.


This comment has been minimized.

Copy link

xhoskin commented Oct 21, 2015

Great! Thnx!

Is it possible somehow to copy a non empty dir in netrw? Tried "let g:netrw_localcopycmd = 'cp -r'", but doesn't work (


This comment has been minimized.

Copy link

nomasprime commented Jul 30, 2016

Thanks, this has been bugging me for ages.


This comment has been minimized.

Copy link

kiryph commented Dec 11, 2016

I was trying to achieve the same on Microsoft Windows 10 with following line:

let g:netrw_localrmdir='C:\Windows/system32/cmd.exe /c rmdir /s /q'

The switch \s is similar to -r.

However, there were issues in the code of netrw-156 in vim8 which require to switch to the more recent netrw-162g version available on

With this new version the variable becomes obsolete:

  *g:netrw_localrmdir*		="rmdir"        Linux/Unix/MacOS/Cygwin  
 				=expand("$COMSPEC")             Windows
				Remove directory command (rmdir)
				This variable is only used if your vim is
				earlier than 7.4 or if your vim doesn't
				have patch#1107.  Otherwise, |delete()|
				is used with the "d" option.

This means your tip does not work anymore.
That's too bad. I was hoping that netrw would offer more convenient default behavior than the command-line. However, there is also the risk that a simple press of D deletes your complete homedirectory. So there is a good reason not to offer such a feature.

The following might be a better reason to re-introduce this variable:
When people want to use programs like rmtrash (OSX) or trash-cli (, they cannot do this anymore.


This comment has been minimized.

Copy link

jordan-acosta commented Jan 12, 2017

If netrw_localrmdir doesn't work for you, remember that, unless you change it, it's just an alias for netrw_rmdir_cmd. Setting that will have the same effect, while maintaining consistent local and remote behavior.

Accidentally deleting directories shouldn't be an issue, either, since netrw requires confirmation before deleting.

See the netrw doc for more info:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.