Quantcast

vim: how to yank only displayed texts in folding

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

vim: how to yank only displayed texts in folding

ping
[retry]
sorry if I posted answered questions since I haven't found a way out yet
for my issues...

I'm using fold a lot and wondering if there is a way to yank ONLY the
displayed texts?
that is , say I have following folding:

     30 hostname "WASHDC core"
     31 +-- 34 lines: aaa new-model
     65 +--  2 lines: !
     67 service password-encryption
     68 baseline show-delta-counts
     69 !
     70 +--  3 lines: controller sonet 12/0
     73 !
     74 +--  3 lines: controller sonet 13/0
     77 !
     78 +-- 23 lines: controller sonet 4/0
    101 +-- 31 lines: !

normally when you yank a folded line, it actually yank the whole texts
that line folded, not only the displayed title.
but I want to also have the option to do the other way -- just yank the
texts that is getting displayed.

this is kind of another good usage of folding -- generate an overview
that can be passed to other places.


regards
ping

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Chris Jones-44
On Sun, May 20, 2012 at 05:28:10AM EDT, ping wrote:

> I'm using fold a lot and wondering if there is a way to yank ONLY the
> displayed texts?
> that is , say I have following folding:
>
>     30 hostname "WASHDC core"
>     31 +-- 34 lines: aaa new-model
>     65 +--  2 lines: !
>     67 service password-encryption
>     68 baseline show-delta-counts
>     69 !
>     70 +--  3 lines: controller sonet 12/0
>     73 !
>     74 +--  3 lines: controller sonet 13/0
>     77 !
>     78 +-- 23 lines: controller sonet 4/0
>    101 +-- 31 lines: !
>
> normally when you yank a folded line, it actually yank the whole
> texts that line folded, not only the displayed title.
> but I want to also have the option to do the other way -- just yank
> the texts that is getting displayed.
>
> this is kind of another good usage of folding -- generate an overview
> that can be passed to other places.

I guess you write a function that uses the following Vim functions to
extract your text and append it to a register:

:h getline()
:h line()
:h foldclose()
:h foldtextexpr()
:h setreg()

And then have mapping such as:

:nmap ,y :g/\n/call MyYank()<CR>

.. to scan the entire buffer so that when you return from MyYank() your
outline would be available in one of the A-Z registers.

I believe you'd need to keep track of whether the current line is the
top line of the fold, or you'd end up with the entire fold appended to
the register.. not what you want obviously.

There are probably less kludgy ways to do that, but that's what comes to
mind..

CJ

--
Alex Perez is aliveeeeeeee!!!

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Christian Brabandt
In reply to this post by ping
Hi ping!

On So, 20 Mai 2012, ping wrote:

> [retry]
> sorry if I posted answered questions since I haven't found a way out
> yet for my issues...

What was wrong with the answer you received last time?
http://groups.google.com/group/vim_use/msg/dd1baac3622107c0

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Chris Jones-44
On Sun, May 20, 2012 at 07:34:36AM EDT, Christian Brabandt wrote:

> Hi ping!
>
> On So, 20 Mai 2012, ping wrote:
>
> > [retry]
> > sorry if I posted answered questions since I haven't found a way out
> > yet for my issues...
>
> What was wrong with the answer you received last time?
> http://groups.google.com/group/vim_use/msg/dd1baac3622107c0

Maybe that I hadn't joined in.. ;-)

Funny that I don't remember seeing that thread and yet came up with the
premises of pretty much the same solution..

CJ

--
Oh My God!!! Larry is back!

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Christian Brabandt
In reply to this post by ping
Hi ping!

On Di, 22 Mai 2012, ping wrote:

> can you let me know how to use this function in practice?
> I tried visual mark then :call func..
> it doesn't work.

Please be exact. What did you do? What happened instead? Did you get an
error message?

>
> http://groups.google.com/group/vim_use/msg/dd1baac3622107c0
>
Take the function CopyNonFoldedI() from here:
http://groups.google.com/group/vim_use/msg/571f070987ee35ce
and copy it into a file which you save below ~/.vim/plugin/CopyFolds.vim

Restart Vim and now you can simply call :call CopyNonFolded() and it
will create a new split buffer which contains only the fold data.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

ping
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?

"yank only non-folded texts
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
"

thanks again for your help!

regards
ping


On 05/22/2012 01:54 PM, Christian Brabandt wrote:
Hi ping!

On Di, 22 Mai 2012, ping wrote:

can you let me know how to use this function in practice?
I tried visual mark then :call func..
it doesn't work.
Please be exact. What did you do? What happened instead? Did you get an 
error message?

http://groups.google.com/group/vim_use/msg/dd1baac3622107c0

Take the function CopyNonFoldedI() from here:
http://groups.google.com/group/vim_use/msg/571f070987ee35ce
and copy it into a file which you save below ~/.vim/plugin/CopyFolds.vim

Restart Vim and now you can simply call :call CopyNonFolded() and it 
will create a new split buffer which contains only the fold data.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Christian Brabandt
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

ping
hi chris:
this works!

thanks!

regards
ping

On May 31, 1:21 am, "Christian Brabandt" <[hidden email]> wrote:

> 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
Loading...