vimtricks.wiki Concise Vim tricks, one at a time.

How do I mark and delete multiple files at once from within Vim's built-in file explorer netrw?

Answer

mf and D (in netrw)

Explanation

Vim's built-in file browser netrw (opened with :Explore or :Ex) supports a full file management workflow beyond simple navigation. Most users only know d (create directory) and D (delete under cursor), but netrw has a mark system that lets you batch-operate on multiple files at once.

How it works

Open netrw with :Explore (or press - if your config maps it), then:

  • mfmark the file or directory under the cursor (a flag appears next to it)
  • mFunmark the file under the cursor
  • muunmark all marked files
  • Ddelete all marked files (prompts for confirmation); deletes the file under cursor if none are marked
  • mt — set a target directory for copy/move operations
  • mccopy marked files to the target directory
  • mmmove marked files to the target directory

Example

Delete several old log files in one pass:

1. :Explore /var/log/myapp
2. Navigate to error.log, press mf
3. Navigate to debug.log, press mf
4. Navigate to trace.log, press mf
5. Press D — all three are deleted after confirmation

Tips

  • mr — mark files using a regexp (prompts for pattern, marks all matches)
  • i — cycle netrw's listing style: thin → long → wide → tree (tree mode is especially useful for project browsing)
  • :Vexplore and :Sexplore open netrw in vertical or horizontal splits
  • Set let g:netrw_banner=0 in your vimrc to hide the header for a cleaner look

Next

How do I detect whether a macro is currently being recorded or executed in Vimscript?