34169Re: Visual block question
- Dec 12, 2003On Fri, Dec 12, 2003 at 08:40:19AM +0100, Miroslaw Dobrzanski-Neumann wrote:
> Some time ago I have asked for pattern matching only in a block.Indeed, search is not a command, it is a function. To run
> But I got now answer.
> Search and replace works fine for me:
> 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
function on a range of lines you need to do
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
Application with visual block is up to you.
- << Previous post in topic Next post in topic >>