Reply to message «Re: search for the last pattern occurrence without moving the cursor», sent 19:41:41 05 May 2011, Thursday by cyboman:
> the idea is not to move the cursor. :$ moves it to the end of file.
> does anybody have any other suggestions.
You can always use
let pattern='copyright \d\{4}'
let crlines=filter(range(1, line('$')), 'getline(v:val)=~#'.string(pattern))
Works only for patterns that match only in one line. You can also try to do the
job with :keepjumps, 'nofoldenable' and winsaveview()+winrestview().
In the above example `crlines' will be set to a list with numbers of lines that
contain a copyright.
Original message:
> the idea is not to move the cursor. :$ moves it to the end of file.
> does anybody have any other suggestions. also please click 'Reply to
> author' so i could get notified.
>
> thanks
>
> On May 5, 11:01 am, "Christian Brabandt" <[email protected]> wrote:
> > On Thu, May 5, 2011 4:55 pm, cyboman wrote:
> > > i'm writing a script to modify the copyright notice. the problem is
> > > that are multiple notices in the file. i need to be able to find a
> > > line where the last notice occurs. vim search() function finds only
> > > the first pattern occurrence. does anybody know of a way to find the
> > > last pattern occurrence?
> > >
> > > here is the example:
> > >
> > > copyright 2008, company a
> > > copyright 2009, company b
> > > copyright 2010, company c
> > > copyright 2011, company d
> > >
> > > i need to be able to find the last occurrence of the following pattern
> > > copyright \d\{4}.
> >
> > Jumping to the last line and searching backwards should work:
> > :$
> > :echo search('copyright \d\{4}', 'bnW')
> >
> > regards,
> > Christian
signature.asc
Description: This is a digitally signed message part.
