Indicator to see from which function a search string comes

谁都会走 提交于 2019-12-23 02:06:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!