sponsor Vim development Vim logo Vim Book Ad

TaggedSearchPattern : Attach names to search patterns for easier recall.

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

created by
Ingo Karkat
script type
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.

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.

Inspired by

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.

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

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
                        You can use CTRL-T CTRL-T to re-tag a tagged search

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
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.

- Requires Vim 7.0 or higher.

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:

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