3

I'm trying to use vidir from the moreutils package and I have the following issue: When I load the files I want to rename with vidir like this:

$ vidir

or like this:

$ find -type f | vidir --verbose -

vidir displays a number, a tab, and the full path of the files like this:

1   ./file1
2   ./file2
3   ./file3

or if it isn't the current folder like this:

1   ./folder/subfolder1/file1
2   ./folder/subfolder1/file2
3   ./folder/subfolder1/file3

Now, I see some advantages in this like the ability to swap file names by swaping the numbers or editing folder names but I just want to rename the files in the same folder and maybe delete some files. My issue is when I use regex to rename the filenames everything could be affected,namely the numbers, the slashes, the dots and the tabs. I tried to remove them at start make my modifications and then rebuild them but vidir complains when I save the file and close the editor.

So how could circumvent this issue? Am I missing something?

EDIT: I tried again to remove the vidir prefix before I start my modifications and add it back when I'm finished and it seems to be working. These are the functions I used in Vim:

" Remove vidir prefix
function! VidirRemovePrefix()
    :%s/\d*\t.\//
endfunction    

" Delete line
function! VidirDeleteLine()
    :s/^\d*\t.*//
endfunction  

" Add vidir prefix back
function! VidirAddPrefix()
    :%s /^/\t.\//
    execute "normal! ggVG"   
    :let i=1 | '<,'>g/^/ s//\=i . ""/ | let i+=1
endfunction

For some reason the last function does not always work. If this is the case then I execute the last line (for inserting the numbers) manually in the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.