How do I rename, move, or delete the current file from inside Vim using vim-eunuch?
Answer
:Rename {newname}
Explanation
vim-eunuch (by Tim Pope) adds Unix shell operations as first-class Vim commands. Instead of leaving Vim to rename or move a file in the terminal, you can do it directly with :Rename, :Move, :Delete, :Mkdir, and more — with the buffer automatically updated to reflect the new path.
How it works
Key commands provided by vim-eunuch:
:Rename {newname}— rename the current file (in the same directory); the buffer's name updates automatically:Move {path}— move the file to a new path (supports different directories):Delete— delete the current file and wipe the buffer:Mkdir {dir}— create a directory (with-pfor nested):Chmod {mode}— change file permissions (e.g.,:Chmod +x):SudoWrite— write the current file with sudo (the classic:w !sudo tee %workaround, built in):SudoEdit {file}— open a file with sudo privileges
Install with your plugin manager: Plug 'tpope/vim-eunuch'
Example
Rename the current file from utils.js to helpers.js:
:Rename helpers.js
The buffer is now associated with helpers.js and the old file is gone — no terminal required.
Tips
:Renameonly changes the filename;:Movecan relocate to a different directory:Deleteasks for confirmation before deleting — unlike:!rm %which deletes without prompting:Chmod +x %then:SudoWriteis the fastest way to make a script executable and save it in one session- vim-eunuch also auto-sets the filetype for new shebang files: creating a new file with
#!/usr/bin/env python3on the first line will setfiletype=pythonautomatically