netrw is often dismissed as a clunky, ancient relic, but its true power lies in its ability to act as a fully-fledged, keyboard-driven file manipulation engine, not just a file browser.

Let’s see netrw in action. Open Vim, and then type :Explore.

:Explore

You’ll see a new buffer appear, listing the files and directories in your current working directory. It looks like this:

/path/to/your/project
.
..
file1.txt
directory1/
another_file.md

Navigate with j and k as usual. To open a file, just press Enter on its name. To enter a directory, press Enter on the directory name.

Here’s a breakdown of how it works and the key commands you’ll want to master:

The Core Problem netrw Solves

The fundamental problem netrw addresses is the friction of context switching. Imagine you’re deep in a Vim session, working on a complex task. To find a related file, create a new one, or rename something, you typically have to:

  1. Save your current buffer.
  2. Open a new terminal window or tab.
  3. Use shell commands (ls, cd, mkdir, mv, cp, rm).
  4. Find the file you need.
  5. Open it in Vim.
  6. Switch back to your original Vim session.

This constant back-and-forth breaks your flow and is incredibly inefficient. netrw brings all these file operations inside Vim, allowing you to manage your project structure without ever leaving your editor.

Internal Mechanics: More Than Just a List

netrw isn’t just a static display of ls output. It’s an interactive buffer that understands file system operations.

  • Buffer Representation: Each netrw buffer is a special type of Vim buffer that dynamically queries the file system. It renders file and directory names, along with metadata like permissions, size, and modification times.
  • Key Bindings: The magic happens through its extensive set of key bindings. These bindings are not just for navigation; they directly trigger file system commands.
  • Directory Navigation: When you press Enter on a directory, netrw doesn’t just open a new buffer for that directory. It replaces the current netrw buffer’s content with the listing of the new directory, maintaining a sense of place.
  • File Operations: Commands like D (delete), R (rename), s (sort), o (open in new split), t (open in new tab) are all mapped to underlying Vim functions that execute shell commands or Vim’s internal file operations.

Essential Commands and Workflow

Let’s dive into the commands that make netrw a powerful tool:

  • :Explore or :E: Opens the netrw browser in the current window for the current directory.
  • :Vexplore or :Vex: Opens netrw in a vertical split.
  • :Sexplore or :Sex: Opens netrw in a horizontal split.
  • Enter (on a file): Opens the file in the current buffer.
  • Enter (on a directory): Navigates into that directory, replacing the current listing.
  • o (on a file/directory): Opens the item in a new horizontal split.
  • v (on a file/directory): Opens the item in a new vertical split.
  • t (on a file/directory): Opens the item in a new tab.
  • D (on a file/directory): Prompts for confirmation and deletes the selected item.
  • R (on a file/directory): Prompts for a new name and renames the item.
  • a (on a directory): Creates a new empty file within that directory.
  • d (on a directory): Creates a new empty directory within that directory.
  • % (on a directory): Creates a new file in the current directory.
  • p (on a file): Copies the file. You’ll be prompted for the destination.
  • m (on a file): Moves the file. You’ll be prompted for the destination.
  • s (in netrw buffer): Cycles through sorting options (name, time, size, extension).
  • r (in netrw buffer): Reverses the current sort order.
  • i (in netrw buffer): Cycles through various listing styles (list, tree, etc.).
  • gh: Toggles showing hidden files (those starting with .).
  • q: Closes the netrw buffer.

Example Workflow:

  1. You’re editing src/main.c.
  2. You need to create a new utility file, src/utils.c.
  3. Type :Vex to open netrw in a vertical split.
  4. Navigate to the src directory by pressing Enter on src/.
  5. Press % to create a new file. Vim will prompt you: New file in src/:. Type utils.c and press Enter.
  6. A new buffer for src/utils.c opens. You can now start coding.
  7. Press q in the netrw buffer to close it.

Configuration and Customization

You can influence netrw’s behavior through Vim’s g: variables.

  • g:netrw_liststyle: Controls the default listing style. 1 for list, 2 for tree.
    let g:netrw_liststyle = 2
    
  • g:netrw_browse_split: Determines how new files/directories are opened. 0 for current window, 1 for vertical split, 2 for horizontal split, 3 for new tab.
    let g:netrw_browse_split = 1
    
  • g:netrw_altfilename: Controls how netrw displays the path. 0 for full path, 1 for relative path.
    let g:netrw_altfilename = 1
    
  • g:netrw_banner: Set to 0 to hide the banner at the top of the netrw buffer.
    let g:netrw_banner = 0
    

The "Hidden" Feature: Editing netrw’s Own Buffer

You can actually edit the netrw buffer itself, which is a powerful, albeit slightly advanced, technique. If you want to rename multiple files or perform complex batch operations, you can modify the filenames directly in the netrw buffer and then press Enter. Vim will interpret these changes as rename or move operations. This is incredibly fast for bulk operations once you’re comfortable with it.

The next logical step after mastering netrw’s file manipulation is to integrate it seamlessly with your project management, perhaps by exploring how netrw interacts with Git or other version control systems.

Want structured learning?

Take the full Vim course →