I have a buffer consisting of many
create view ...
...
go
blocks.
How can I write these blocks somehow efficient to different files?
This presumes a little stability in your source (that there's
consistent spacing/indenting, that case is consistent, that the
view-name immediatedly follows as in "create view vwMyView", and
that the terminating "go" appears alone on the line, etc)
:g/^create view\>/exec '.,/^go$/w '.matchstr(getline('.'),
'create view \+\zs\w\+').'.sql'
might do the trick for you.
It would be less complex if it didn't try and extract the
view-name from your CREATE VIEW statement, but it's kinda the
extra-mile :)
Alternatively, if you wanted to just use sequential numbers, you
could do something like
:let x=0|g/^create view\>/exec '.,/^go$/w '.printf("%05d",
x).'.sql'|let x +=1
I think the printf() was added in Vim7 so this is a little uglier
if you have to get it working on earlier versions...or if you
don't need them zero-padded to N (where in the above, N=5) digits
for sorting purposes, you can just use
:let x=0|g/^create view\>/exec '.,/^go$/w '.x.'.sql'|let x +=1
Just a couple ideas.
-tim