sponsor Vim development Vim logo Vim Book Ad

TaggedSearchPattern : Attach names to search patterns for easier recall.

 script karma  Rating 5/4, Downloaded by 162    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
You use text searches all the time in Vim. While it is simple to recall
previous patterns through the cmdline-history, quickly recognizing them can
be hard, especially if it's a long convoluted regular expression that you've
confidently built some hours ago, but now all variants stored in the history
look like nearly identical gibberish.

This plugin allows you to "tag" individual searches with a name, so that these
searches are documented and therefore become easier to recognize and recall.
You can also pre-seed your search history with frequently needed searches.

HOW IT WORKS
Tagged searches reside in the normal search history like all other searches.
The tagging works by prepending a special regular expression branch that never
matches any text.

RELATED WORKS
Inspired by
http://stackoverflow.com/questions/10174171/indicator-to-see-from-which-function-a-search-string-comes/

An alternative is to append a literal NUL character (^@, enter via <C-V><C-@>)
after the concluded search pattern, e.g.
    /foobar/^@tag here
Vim will ignore everything after the NUL byte, but it'll still show the whole
line in the search history, including the tag. (Discovered by glts in
http://stackoverflow.com/a/20020360/813602) This depends on an implementation
detail, and the tag position makes it more difficult to search / recall.

USAGE
Inside the search command-lines (:/, :?), tag (and un-tag) the current
search with CTRL-T, type the tag name, and store and activate the search with
<Enter> as usual.
Since tagged searches start with the tag, recall is as simple as entering the
search command-line via :/, typing the first letters of the tag and pressing
c_<Up> (repeatedly if there are many).
When you're in the cmdline-window via q/, just search for tags via
/^{tag-name}. Or open a filtered view of the search cmdline-window through
q_CTRL-T.

CTRL-T                  Prepend the search-neutral tag expression and position
                        the cursor before it at the beginning of the
                        command-line, so that the tag can be entered.
                        For the tag, stick to alphanumeric characters
                        (whitespace is okay, too). Do not use characters like
                        \, &, |, etc. that have a special meaning in a regexp!

                        When the current search already has been tagged:
                        Remove the tag and the following search-neutral tag
                        expression.
                        You can use CTRL-T CTRL-T to re-tag a tagged search
                        pattern.

q CTRL-T                Open the search command-line window as with q/ and
                        list only tagged searches. The tag names are
                        highlighted for easier recognition. As usual, <Enter>
                        uses the current search pattern under the cursor, or
                        press CTRL-C to continue editing in Command-line mode.
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vba.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 TaggedSearchPattern.vba.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.


CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

To turn off the highlighting of the tag name and search-neutral tag expression
in the search cmdline-window:
    let g:TaggedSearchPattern_HighlightTags = 0

To change the highlighting colors, redefine or link the two highlight groups:
    highlight link TaggedSearchTag Search
    highlight TaggedSearchNeutral ctermfg=Black guifg=White
 

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
TaggedSearchPattern.vba.gz 1.00 2012-07-09 7.0 Ingo Karkat Initial upload
ip used for rating: 54.82.31.133

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