Linux – rename files in a directory with Vim

batch-renamelinuxrenamevim

If I open a directory in vim using vim . I will get a file-browser-type interface of the current directory. From there I am expected to browse to a file, and then start editing it.

I want to use this interface to rename files. Normal vim rename works like %s/term1/term2/, but when I try it out here, it returns: E21: Cannot make changes, 'modifiable' is off.

Is there a way to turn modifiable on in this scenario, or does this simply mean that it cannot be done like this with vim?

Best Answer

Yes, it can't be done like that.

That "file-browser-type interface" is provided by a built-in plugin called netrw. It is read-only so yeah, you can't modify it.

You are supposed to hit R to rename the file under the cursor or the marked files.

See :help netrw, :help netrw-browse-maps and more specifically :help netrw-R.

If you want to batch-rename files using Vim you should try qmv from the renameutils package or vidir from the moreutils package (thanks to Dmitry for the heads up).

Related Question