Skip to content

Instantly share code, notes, and snippets.

@hovsater
Last active October 21, 2021 08:58
Show Gist options
  • Save hovsater/5068370 to your computer and use it in GitHub Desktop.
Save hovsater/5068370 to your computer and use it in GitHub Desktop.
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

@tatethurston
Copy link

If your vim has 7.4 with patch#1107, then |g:netrw_localrmdir| no longer
is used to remove directories; instead, vim's |delete()| is used with
the "d" option.  Please note that only empty directories may be deleted
with the "D" mapping.  Regular files are deleted with |delete()|, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment