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

How do I rename files directly from Vim's built-in netrw file browser?

Answer

R (in netrw)

Explanation

Vim's built-in file explorer netrw lets you rename files and directories without leaving the editor. By pressing R on a file entry in the netrw listing, you can rename or even move a file to a different directory. This saves you from switching to a terminal just to perform basic file management.

How it works

  • Open netrw with :Explore (or :Ex for short)
  • Navigate to the file you want to rename
  • Press R with the cursor on the target file
  • netrw prompts you for the new name, pre-filled with the current path
  • Edit the name and press <CR> to confirm, or <Esc> to cancel

Example

With the netrw listing showing:

" netrw
../
./
old-name.txt
utils.py

Place your cursor on old-name.txt and press R. The command line shows:

Moving /project/old-name.txt to : /project/old-name.txt

Edit the target path to /project/new-name.txt and press <CR>. The file is renamed immediately.

Tips

  • You can move a file to a different directory by changing the path portion of the name
  • Use d in netrw to create a new directory and D to delete a file
  • Press % in netrw to create a new file in the current directory
  • These operations work on remote files too if netrw is connected via scp:// or ftp://

Next

How do I display the full absolute path of the current file in Vim?