Hi,

The problem I am trying to solve is as follows:

I have a file consisting of a load of filenames, one per line. These files need 
to be moved into sequentially ordered subdirectories, so I want to edit the 
file so it goes from:

----------
aaa.txt
bbb.txt
ccc.txt
----------

to

----------
mv aaa.txt sub001
mv bbb.txt sub002
mv ccc.txt sub003
----------

What I originally tried was something like the following on the VIM command 
line:

----------
:1,$s/.*/\=printf("mv & sub%03s", line("."))
----------

but then I discovered that '&' does not get expanded to the search string in 
functions. Checking the help confirms this fact.

What I've resorted to doing for the moment is using the following substitute to 
get the subdirectories on the end:

----------
:1,$s/$/\=printf(" sub%03s", line("."))
----------

Followed by the following to get the 'mv' commands at the beginning:

----------
:1,$s/^/mv /
----------

I'm currently thinking about writing a function to do the replacements, but is 
there a simpler way of doing this in VIM?

Spencer Collyer


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to