Re: reorder files with a mouse in a file browser and rename them
H.S. wrote:
>>
>> file2.txt
>> file3.txt
>> file1.txt
>>
Assume that you were somehow able to generate this list. In real life
problem, this would be couple hundred lines long (not just 3 lines). Call
this listA.
>> to
>>
>> 001_file2.txt
>> 002_file3.txt
>> 003_file1.txt
>
Call this listB. Let's see how listA can be changed to listB inside vim.
$cat temp.txt
file2.txt
file3.txt
file1.txt
file5.txt
file9.txt
file10.txt
file8.txt
$cp temp.txt temp1.txt
open temp1.txt in normal mode, put your cursor in line 1, column 1. Now
enter the following letters.
i001_<ESC>|
qavf_yjPh<ctrl-a>|q
5@a
:w
after this you should have temp1.txt as
$cat temp1.txt
001_file2.txt
002_file3.txt
003_file1.txt
004_file5.txt
005_file9.txt
006_file10.txt
007_file8.txt
$paste temp.txt temp1.txt > temp2.txt
$cat temp2.txt
file2.txt 001_file2.txt
file3.txt 002_file3.txt
file1.txt 003_file1.txt
file5.txt 004_file5.txt
file9.txt 005_file9.txt
file10.txt 006_file10.txt
file8.txt 007_file8.txt
now open temp2.txt in normal mode in vim, put the cursor at line 1, column
1. enter the following commands
<ctrl-v>G
I
mv <ESC>
:w
$cat temp2.txt
mv file2.txt 001_file2.txt
mv file3.txt 002_file3.txt
mv file1.txt 003_file1.txt
mv file5.txt 004_file5.txt
mv file9.txt 005_file9.txt
mv file10.txt 006_file10.txt
mv file8.txt 007_file8.txt
Voila! your script is ready. You can add
#! /bin/sh at the top of temp2.txt and make it executable. It can be run by
./temp2.txt
inside bash.
Explanation of some of the vim commands.
i001_<ESC>|
insets 001_ and moves the cursor to the begining of the line.
qavf_yjPh<ctrl-a>|q
record some commands in register a.
5@a
execute the commands in register a, 5 times. If the number of files in listA
is 100, you will do 100@a instead of 5@a.
:w
write the file.
hth
raju
--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/
Reply to: