Monday, August 15, 2011

Re: Get selected line(s) using Perl

On Aug 16, 4:17 am, "Daniel Sand" <daniel.m.s...@gmx.de> wrote:
>based on the help topic **perl-overview**, $curbuf->Get($startline, $endline) can be used to retrieve arbitrary lines in the current >
>buffer based on their absolute line numbers.

That doesn't work the way you appear to be imagining it does. That
gets two lines, the first and the last. I think you want
$curbuf->Get($startline .. $endline)

> Is there a way to Get exactly those lines that have been selected by the user in the current buffer?

You can use the VIM:Eval() method with vim's getpos function on the '<
and '> marks. F.ex.

perl ($success, $startline) = VIM::Eval('getpos("\'<")[1]')
perl ($success, $endline) = VIM::Eval('getpos("\'>")[1]')
perl @lines = $curbuf->Get($startline .. $endline)

(The return value in perl of vim's getpos function is tricky, so the
above selects the line number element with vim's syntax.)

HTH, John

--
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: