On 12 August 2010 17:37, Jürgen Krämer <[email protected]> wrote:
>
> Hi,
>
> James Kanze wrote:
>> I'm currently editing some files which contain several more or
>> less independent sets of data.  At any one time, I'm generally
>> working on one, and only one set, delimited as a contiguous
>> range of lines.  I'd like to limit all of the search commands to
>> only consider this range.
>>
>> I'm aware of using \%<'m and \%>'m in the search string, but
>> this has to be entered each search.
>>
>> My initial idea was to fold the regions before and after the
>> range, but this doesn't seem to stop the search, and it
>> automatically opens the fold when it finds something in the
>> folded text.  I want it to not search in the folded text.  Is
>> there some option to make search ignore folded text, or some
>> other way of achieving what I want.
>
> depending on how you define those sets of lines you can also use
> 'searchpair()' if the cursor is currently inside the block you want
> to search through. Wrapped in a command this would look something like
>
>  :command -nargs=1 SearchInSet  call searchpair('^BEGIN$', <q-args>, '^END$')
>
> if those set of lines are delimited by BEGIN and END. You can than use
> this command with
>
>  :SearchInSet search-string
>
> Regards,
> Jürgen

I give an alternate way

function! VModeSearchRange()
        return '\%>' . ( line("'<") - 1 ) . 'l\%<' . ( line("'>") + 1 ) .  'l'
endfunction

vnoremap / <ESC>/<C-R>=VModeSearchRange()<CR>

You can v-select the range you want to search and then press "/",
continue type the word you want to search.

>
> --
> Sometimes I think the surest sign that intelligent life exists elsewhere
> in the universe is that none of it has tried to contact us.     (Calvin)
>
> --
> 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 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

Reply via email to