On Thu, August 6, 2009 11:36 pm, drlatex wrote:
>>
> asdf....|name1|....asdf
>>
> asdf....|name2|..asdf
>>
> asdf....|name3|....asdfa
>
> where the ellipses (dots) represent large amounts of letters, and there
> are
> 500 sections separated by '>'
>
> I want, instead of this one big file, 500 smaller files that only have '>'
> once:
Try this
fu! <SID>Split(flag, dir)
let cwd=getcwd()
try
exe 'lcd ' . a:dir
catch
echoerr 'Directory is wrong. Aborting'
endtry
let op = getpos('.')
0
while 1
let lline=search('^[^>]','Wn')
if lline==0
break
endif
let filename=matchstr(getline(lline), '|\@<=[^|]\+')
try
exe line('.') . ',' . lline . 'w' . (a:flag ? '! ' : ' ') . filename
catch
echoerr 'file ' . filename . ' already exists, not saving,
aborting'
endtry
exe lline+1
endwhile
call setpos('.',op)
exe 'lcd ' . cwd
endfu
com! -nargs=1 -bang -complete=dir SplitFile
\:call <SID>Split(empty('<bang>') ? 0 : 1, <q-args>)
regards,
Christian
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---