Loading ...
Sorry, an error occurred while loading the content.

64354Re: limit search scope

Expand Messages
  • bill
    Jan 1, 2006
    • 0 Attachment
      Charles E. Campbell, Jr. wrote:

      > bill wrote:
      >
      >> I often would like to limit the scope of a search (for example,
      >> searching for a variable name only in the current code block.)
      >>
      >> <snip>
      >> I have a plugin that will do that! You'll find it at my website,
      >
      <snip>

      I've added the following lines to my .vimrc, attempting to
      map '/' and 'n' to your function, relying on the global variable
      limit_search_scope to either call the limiting function, or the
      normal search function. It doesn't quite work right, and I'm hoping
      someone can shed light on it. Here's what's in my .vimrc:

      nmap / :call Search(1)<cr>
      nmap n :call Search(0)<cr>

      function! Search(prompt_needed)
      if g:limit_search_scope == 1
      if a:prompt_needed
      let @/ = input('FS/')
      endif
      normal :FS
      else
      if a:prompt_needed
      let @/ = input('/')
      endif
      call search(@/)
      endif
      endfunction

      (note that I'm using a modified version of Chip's function which
      searches for @/ if no argument is passed)
      This works very well, except that 'n' doesn't. I can
      use / with a limited search and @/ gets set properly, at which
      point I can use the mapping with 'n' if g:limit_search_scope
      is not set, and I can do ':FS' to get the repeated limited search to
      happen, but
      the mapping 'n' fails if the search is limited. Can anyone explain why
      it fails?
      (If g:limit_search_scope
      is set and I do 'n', absolutely nothing (seems to) happen).
    • Show all 5 messages in this topic