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

How do I create new files and directories directly inside Vim's built-in file browser without leaving Vim?

Answer

% (in netrw)

Explanation

Vim's built-in file explorer netrw (opened with :Explore or :Ex) is more capable than it looks. You can create files, create directories, rename, and delete — all without dropping to a shell or using an external file manager.

How it works

Key netrw file management commands (pressed while inside netrw):

  • % — create a new file in the current directory (prompts for a name, then opens it for editing)
  • d — create a new directory (prompts for a name)
  • R — rename the file or directory under the cursor
  • D — delete the file or directory under the cursor (prompts for confirmation)
  • - — navigate up to the parent directory

Example

  1. Open netrw: :Ex or :Explore
  2. Navigate to your target directory
  3. Press % and type newfile.py to create and open a new Python file
  4. Press d and type src to create a new directory named src
  5. Press R over an existing file to rename it

Tips

  • D on a directory only works if it is empty; use your shell for non-empty directories
  • Press i to cycle between listing styles (thin, long, wide, tree)
  • Set let g:netrw_banner = 0 in your vimrc to hide the help banner and get more space
  • :Vexplore opens netrw as a vertical split so you can keep it open while editing
  • All netrw operations work on remote files too (SSH, FTP) when opening scp://host/path

Next

How do I join a specific number of lines at once without pressing J multiple times?