I searched the vim help but couldn't anything connecting folds and hard copy or
printing.
Can someone tell me if or how I can generate a printout from vim that will
include only the text I want and replace the rest with markers, something like
those used for folds.
Currently using vim 7.1.
Cheers,
Andrew Chalmers.
:help :TOhtml
This function can be used with a range, converts your file to HTML (in a
new window), showing the syntax highlights and displaying the folds the
way they are.
Then you can load the result in your favourite browser and print from there.
Best regards,
Tony.
--
If you had any brains, you'd be dangerous.
Thanks Tony.
I don't suppose there is a plain text equivalent, to save me having to load up a
browser?
Thanks,
Andrew.
AFAIK, there isn't.
Best regards,
Tony.
--
Occident, n.:
The part of the world lying west (or east) of the Orient. It
is largely inhabited by Christians, powerful sub-tribe of the
Hypocrites, whose principal industries are murder and cheating, which
they are pleased to call "war" and "commerce." These, also, are the
principal industries of the Orient.
-- Ambrose Bierce, "The Devil's Dictionary"
I once posted this in a different topic. The function returns
a list of lines of the current buffer with respect to folds.
func! FoldedToText( )
let res = []
let l = 1
while l <= line('$')
if foldclosed(l) != -1
let res+= [ foldtextresult(l) ]
let l = foldclosedend(l)
else
let res+= [ getline(l) ]
endif
let l+=1
endwhile
return res
endfun
call writefile(FoldedToText(),'/tmp/bar')
-ap
Well I guess you could use a function that would return all non-folded
text. Something like this might actually work for you:
function CopyNonFolded()
let lnum=1
let buffer=[]
while lnum <= line("$")
if (foldclosed(lnum) == -1)
let buffer += getline(lnum, lnum)
let lnum += 1
else
let buffer += [ foldtextresult(lnum) ]
let lnum = foldclosedend(lnum) + 1
endif
endwhile
top new
set bt=nofile
call append(".",buffer)
0d_
endfu
This function will copy all non folded text into a new buffer, from
which you could easily print the text.
Note, that I do write vim functions only occasionally, so there might be
better ways to do what you like to achieve.
regards,
Christian
Before writing complicated functions, keep in mind the :folddoopen and
:folddoclosed commands.
I'm not sure of an exact method to use them for this application, but
I'm sure they'll be useful.