sponsor Vim development Vim logo Vim Book Ad

SearchInRange : Limit search to range when jumping to the next search result.

 script karma  Rating 1/1, Downloaded by 56    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
Vim can limit the scope of searches to the remainder of the buffer with the
'wrapscan' option, but it cannot limit searches to a particular range, other
than by including special regular expression atoms like /\%l. It's not easy
to restrict a search to the current function, or next 100 lines, even though
such is often useful to avoid getting lost in the buffer.

This plugin provides custom search motions, similar to the built-in n / N,
which only move to matches of the current search pattern that fall within a
certain range that has been specified through the :SearchInRange command, or
an equivalent mapping.

RELATED WORKS
- range-search (vimscript #1396) defines a :R command.
- vis.vim (vimscript #1195) defines a :S command and // and ?? mappings. It
  works by modifying the search pattern to add restrictions for lines and
  columns.

USAGE
:[range]SearchInRange   Search forward to the first occurrence of the current
                        search pattern inside [range]. Limit search to lines
                        inside [range] when jumping to the next search result.
:[range]SearchInRange [/]{pattern}[/]
                        Search for {pattern}, starting with the first
                        occurrence inside [range]. Limit search to lines
                        inside [range] when jumping to the next search result.
                        Without [/], only literal whole words are matched.
                        :search-args

{Visual}<Leader>n       Jump to the first occurrence of the last search
                        pattern inside selection. Limit search to lines inside
                        selection when jumping to the next search result.

<Leader>n{motion}       Use the moved-over lines as a range to limit searches
                        to. Jump to first occurrence of the last search
                        pattern inside the range.

The special searches all start with 'go...' (mnemonic: "go once to special
match"); and come in search forward (ending with lowercase letter) and search
backward (uppercase letter) variants.

[count]gor / goR        Search forward / backward to the [count]'th occurrence
                        of the last search pattern in the previously specified
                        range.
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim SearchInRange*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.022 or
  higher.
- SearchRepeat.vim (vimscript #4949) plugin (optional)

INTEGRATION
If the SearchRepeat plugin is installed, a parallel set of "go now and for
next searches" mappings (starting with 'gn...' instead of 'go...') is
installed. These mappings have the same effect, but in addition re-program the
'n/N' keys to repeat this particular search (until another gn... search is
used).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
SearchInRange-1.01.vmb.gz 1.01 2014-09-26 7.0 Ingo Karkat - FIX: Need to explicitly account for closed folds in the range passed to SearchInRange#SetAndSearchInRange().
- FIX: When moving to start / end of range, must use "c" search flag to avoid skipping a match directly at the border.
- FIX: After moving outside the range, also need to use "c" search flag.
- FIX: Correct default mappings in documentation. *** You need to update to ingo-library (vimscript #4433) version 1.022! ***
SearchInRange-1.00.vmb.gz 1.00 2014-08-06 7.0 Ingo Karkat Initial upload
ip used for rating: 54.81.112.187

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo