sponsor Vim development Vim logo Vim Book Ad

MultipleSearch : Highlight multiple searches at the same time, each with a different color.

 script karma  Rating 649/257, Downloaded by 10063    Comments, bugs, improvements  Vim wiki

created by
Dan Sharp
 
script type
utility
 
description
MultipleSearch allows you to have the results of multiple searches displayed
on the screen at the same time.  Each search highlights its results in a
different color, and all searches are displayed at once.  After the maximum
number of colors is used, the script starts over with the first color.

The command syntax is:
:Search <pattern1>
which will highlight all occurrences of <pattern1> in the current buffer.  A
subsequent :Search <pattern2> will highlight all occurrences of <pattern2>
in the current buffer, retaining the highlighting of <pattern1> as well.
<pattern1> and <pattern2> are any search pattern like you would use in a
normal /<pattern> search.

The :Search command honors Vim's 'ignorecase' and 'smartcase' settings for
its own search.  You can use the \c and \C flags in the search pattern to
force case matching no matter the setting of 'ignorecase' and 'smartcase'.

The :SearchBuffers command works just like :Search, but the search occurs in all currently listed buffers (i.e., appear in the output of :ls).  The match in all buffers will have the same color.  This is different than  :bufdo Search <pattern> because in that case, each buffer will highlight the match in a different color.  Thanks to Jeff Mei for the suggestion!

To clear the highlighting, issue the command
:SearchReset (for the current buffer) or :SearchBuffersReset (for all buffers).

You can specify the maximum number of different colors to use by setting the
g:MultipleSearchMaxColors variable in your .vimrc.  The default setting is
four, but the script should handle as much as your terminal / GUI can
display.  The g:MultipleSearchColorSequence variable lets you list the
colors you want displayed, and in what order.  To make the text more
readable, you can set the g:MultipleSearchTextColorSequence variable to a
list of colors for the text, each position corresponding to the color in the
same position in g:MultipleSearchColorSequence.

If you change one of the preference variables, you can issue the command
:SearchReinit
to update the script with your new selections.
 
install details
Copy the MultipleSearch.vim file into your local plugins directory, restart (g)vim, and you are ready to go.
 

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
MultipleSearch.zip 1.3 2008-09-23 6.0 Dan Sharp New mappings:
n and N : jump to next / previous match of current ':Search' pattern
<Leader>n and <Leader>N : jump to next / previous ':Search'-ed pattern
<Leader>* : perform a :Search of the word under the cursor / visually selected region

Other changes:
Supports Vim 7 autoload mechanism, but will still work under Vim 6
Bug fixes to escape characters in the search pattern
MultipleSearch.vim 1.2.1 2003-10-14 6.0 Dan Sharp Add the :SearchBuffersReset command to clear the highlighting in all buffers from the new :SearchBuffers command.
MultipleSearch.vim 1.2 2003-10-13 6.0 Dan Sharp Added the :SearchBuffers command to perform the same search in all open buffers.  This is different than ':bufdo Search' where each buffer will have the match highlighted in a different color.
MultipleSearch.vim 1.1 2002-11-19 6.0 Dan Sharp - :Search command now respects Vim's 'ignorecase' and 'smartcase' settings.
- User-defined color sequence can be used for searches.
- Maximum number of colors that can be used is limited only by the operating system.
MultipleSearch.vim 1.0 2002-11-11 6.0 Dan Sharp Initial upload
ip used for rating: 54.83.227.6

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