As it happens you sometimes end up with a bunch of files which you would rather rename to something else and it'd be pretty sweet to just rename them like you would search and replace strings while working with Vim. Guess what, there's a tool just like that and it's fittingly called massren.
The instructions on how to install this tool are on the Github page of the project. If you are on a Mac just use homebrew as usual.
brew tap laurent22/massren brew install massren
This will tap a specialized repository because it's not in the main Homebrew formulas (yet?). One of the main dependencies is
go so this will probably take a minute to install.
Now just tell massren to use Vim as the default editor with:
massren --config editor "vim"
If you are already familiar with string manipulation in Vim you already know how to rename files with massren.
The working directory:
demo|⇒ ls blah0.txt~ blah2.txt~ blah3.txt~ blah4.txt~
Navigate to the directory where your files are located and type
massren. It'll open the regular Vim editor and you will see a list of all the files in the directory.
Our goal is to remove all these nasty
~ from the filename of these automatically created backup files.
Now we are just going to use Vim expression we are all familiar with already. If you are not there's a wiki explaining the various expressions.
Just type the following expression (Don't forget to escape the tilde) and confirm by pressing
If you see something like "4 substitutions on 4 lines" it worked. Now we just have to save our "file" like we always do. Use
:wq to save and quit Vim.
The output should look like this:
demo|⇒ ls blah0.txt~ blah2.txt~ blah3.txt~ blah4.txt~ demo|⇒ massren massren: Waiting for file list to be saved... (Press Ctrl + C to abort) demo|⇒ ls blah0.txt blah2.txt blah3.txt blah4.txt demo|⇒