问题
I have a number of functions that create search strings @/
I would like to know from which functions comes the search string.
Is it possible to add an indicator to the search string that doesn't influence the search string but what allows me to check from which function it comes?
p.e. /[indicator]search string
回答1:
You can add a regexp branch that never matches, e.g. /\%$indicator\|search string
\%$
is a special Vim atom matching the end of the file. Since that will never match when followed by the indicator text, the first branch (up to \|
) will never match and therefore can represent your indicator.
Note that you cannot just use the $
atom, since it matches the end-of-line only at certain places in the regexp, and a literal $ otherwise. (The same applies to other atoms like ^
and []
, so only some special Vim atoms (\%c
is another one) can be used safely. Thanks to ib for pointing this out!)
回答2:
I have turned this idea into a Vim plugin: TaggedSearchPattern: Attach names to search patterns for easier recall.
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.
来源:https://stackoverflow.com/questions/10174171/indicator-to-see-from-which-function-a-search-string-comes