Thursday, February 26, 2015

Re: Defining Region focused on current page

On 2015-02-26, Paul Isambert wrote:
> Le jeudi 26 février 2015 à 04:57, Ni Va a écrit:
> > On Thursday, February 26, 2015 at 4:31:40 PM UTC+1, Gary Johnson wrote:
> > > On 2015-02-26, Ni Va wrote:
> > > > Hi,
> > > >
> > > > I would like to define a region based on current page displayed of
> > > > opened buffer.
> > > >
> > > > How can I define that ?
> > >
> > > I don't know what you mean by "define a region", but you can
> > > visually select all the lines on the current displayed page with
> > >
> > > HVL
> > >
> > > H moves the cursor to the first line of the window; V starts
> > > visual mode linewise; L moves the cursor to the last line of the
> > > window.
> > >
> > > Regards,
> > > Gary
> >
> > Hi Gary,
> >
> > I know visual selection but I just want to define a region to set this command line :
> >
> > syntax sync region ... in order to do syn only on current displayed page
>
> See ":help \%l" and ":help line()" (especially with "w0" and "w$") and
> you should be able to do something like:
>
> exec 'syntax region YourRegion start=+\\%' . line('w0') . 'l+ end=+\\%' . line('w$') . 'l+'

The trouble with that is that the line() functions are evaluated
only at the time the exec command is executed, so the region remains
the lines in the window at the time the syntax file was sourced.

I discovered that the other day when I tried doing something similar
with matchadd(), \%l and line("'a"). After seeing the result, it
was "obvious" why it failed. I wound up evaluating the matchadd()
in a CursorHold autocommand.

Regards,
Gary

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: