Wednesday, May 30, 2012

Re: vim: how to yank only displayed texts in folding

On Wed, May 30, 2012 20:17, ping wrote:
> hi Christan:
> yes that works!
> thanks!
>
> previously I got it wrong that I visually selected my text and apply
> the function with that range.
>
> b.t.w can we actually achieve that goal based on your function here?

I think, this should do:

function! CopyNonFolded() range
let lnum= a:firstline
let buffer=[]
while lnum <= a:lastline
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

com! -range=% CopyFolds :<line1>,<line2>call CopyNonFolded()

You can then use the command Copyfolds with or without a selected range
(in which case it selects the complete file).

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment