vmv : group rename files from the command prompt with vim
| script karma
Downloaded by 579
Comments, bugs, improvements
script versions (upload new version)
|vmv - the vim version of the mv command. This script is in intent exactly the same as renamer.vim, rename a mass of files all at once using the full power of vim's editing capabilities. Usage is much simpler to remember if you haven't used it in months, and the script itself is much shorter. Great for anybody who just ripped a CD to "track 01.mp3" through "track 12.mp3", or just inherited a collection of mp3's without proper case and with underscores instead of spaces.
Also notable is that this will deal with files that start with a - or -- just fine.
Usage is simple:
1. Give it a list of files to be renamed.
2. Edit that list to reflect what you want the file names to be.
3. ":wq" and you're done
Here's a few examples:
#Rename all non-hidden files in the current directory
#Rename all mp3 files below the current directory
localhost~$find | grep -i '\.mp3$' | vmv
#Rename all files listed in file "list.txt"
#Note that the file list.txt will be saved as well as files on disk renamed.
There are two "bugs" that I know of:
1. It remembers the previous name of the file via line number, so if you add or delete lines bad things may happen.
2. It renames files directly to the destination filename, so trying to swap filenames will instead overwrite the second with the first, and rename the second as the first. Probably not what you wanted, but the fix is too complicated and the case rare enough that I didn't bother to implement it.
3. It's fairly slow when writing large lists of files, even if only a few where modified. Some better way of storing the meta-data (i.e. original name) is needed.
There isn't really much error checking. If the original file name doesn't exist, that line will fail with a message, but it will merrily proceed with the rest of the file. If the destination file name already exists it will overwrite without warning. There is no lifeguard, swim at your own risk. I was going to write fixes for those, and also make it check if the file exists when it's first loaded for editing. I changed my mind because, after all, <sarcasm> I know what I'm doing. </sarcasm> Yes, the 0.1 version number is correct. It's functional, and does what I need it to do, and little else.
If you enjoy this script, and want it improved, your comments would be helpful.
|0. ungz and untar the files.
1. Copy the bash script "vmv" into a directory in your path.
2. Save the vmv.vim file somewhere.
3. Edit the "vmv" bash script to reflect the correct location of vmv.vim.
4. Use as per examples above.
Note that the suppled shell script uses stty to determine if stdin is a pipe or not, so you'll need a shell and stty to use the script. Most, if not all, unix systems will already have both. The #! at the beginning of the script specifies bash, but it'll probably work with other shell programs as well.
Click on the package to download.
ip used for rating: 188.8.131.52