34170Re: Visual block question
- Dec 12, 2003On Fri, Dec 12, 2003 at 04:02:16AM -0500, Pavol Juhas wrote:
> On Fri, Dec 12, 2003 at 08:40:19AM +0100, Miroslaw Dobrzanski-Neumann wrote:Thaks, it works fine for me
> > Some time ago I have asked for pattern matching only in a block.
> > But I got now answer.
> > Search and replace works fine for me:
> > :'<,'>s/a/b/g
> > There seems to be no command for searching only. I've tried
> > :'<,'>search (a)
> > but but vim tells me: "search is not an editor command" althogh documented in
> > eval.txt
> Indeed, search is not a command, it is a function. To run
> function on a range of lines you need to do
> :'<,'>call search('a')
> but it would probably not do what you want - search() function does
> not accept range, so it would be executed for every line in '<,'>
> and it would find the first 'a' after '>.
> OK, here it is - save and source the following lines and try
> :1,5call RangeSearch('a') this should match 'a' in lines 1-5.
> function! RangeSearch( pat ) range
> " match on the firstline or below
> let pbeg = '\(\%' . a:firstline . 'l\|\%>' . a:firstline . 'l\)'
> " match on the lastline or above
> let pend = '\(\%' . a:lastline . 'l\|\%<' . a:lastline . 'l\)'
> let @/ = pbeg . '\&' . pend . '\&' . a:pat
> normal! n
> Application with visual block is up to you.
This message is utf-8 encoded
- << Previous post in topic Next post in topic >>