在vimscript regex字符串中,+符号是什么意思

时间:2022-12-22 22:30:37

You can find this syntax being commonly used in syntax vimscripts. For example you can find it in the file <vimdir>\syntax\python.vim on line 113 in vim 7.4 (win7):

您可以发现在语法vimscripts中通常使用这种语法。例如,您可以在文件 \语法\python中找到它。vim 7.4 (win7)第113行:

syn match pythonEscape +\\[abfnrtv'"\\]+ contained

My simple question is what do the + signs mean at the either end of the regex string literal?

我的简单问题是,在regex字符串的两端,+符号是什么意思?

I could not find anything with :help literal-string and :help regex or steve losh's book. Where do you think I should have been looking?

我找不到任何帮助:帮助字符串和:帮助regex或steve losh的书。你觉得我应该去哪儿找?

1 个解决方案

#1


3  

They are indeed the start and end of the regex, in vim you can use any character as a delimiter. I remember reading this in Drew Neil's book "Practical Vim", but I also found an example here: http://www.hacktux.com/vi/replace

它们确实是regex的开始和结束,在vim中,您可以使用任何字符作为分隔符。我记得在德鲁·尼尔(Drew Neil)的书《实践Vim》(Practical Vim)中读到过这个,但我也在这里找到了一个例子:http://www.hacktux.com/vi/replace

Escaping Characters

转义字符

You will have to escape out the slash if it is part of your search string:

如果斜杠是搜索字符串的一部分,则必须将其转义:

%s/http:\/\//https:\/\//g

% s / http:\ \ / / https:\ \ / / g

Use Any Delimiter

使用任何分隔符

Alternatively, change your delimiter. It can be anything!

另外,改变你的分隔符。它可以是任何东西!

%s!http://!https://!g

% s ! http://,https:// ! g

From sidyll in the comments:

来自sidyll的评论:

Just for the sake of completeness, you may want to add the official help reference: :h E146. This is explained in the flags section, one of the last paragraphs at :h s_flags

为了完整起见,您可能需要添加官方的帮助引用::h E146。这在flags部分中得到了解释,这是h s_flags的最后一段

#1


3  

They are indeed the start and end of the regex, in vim you can use any character as a delimiter. I remember reading this in Drew Neil's book "Practical Vim", but I also found an example here: http://www.hacktux.com/vi/replace

它们确实是regex的开始和结束,在vim中,您可以使用任何字符作为分隔符。我记得在德鲁·尼尔(Drew Neil)的书《实践Vim》(Practical Vim)中读到过这个,但我也在这里找到了一个例子:http://www.hacktux.com/vi/replace

Escaping Characters

转义字符

You will have to escape out the slash if it is part of your search string:

如果斜杠是搜索字符串的一部分,则必须将其转义:

%s/http:\/\//https:\/\//g

% s / http:\ \ / / https:\ \ / / g

Use Any Delimiter

使用任何分隔符

Alternatively, change your delimiter. It can be anything!

另外,改变你的分隔符。它可以是任何东西!

%s!http://!https://!g

% s ! http://,https:// ! g

From sidyll in the comments:

来自sidyll的评论:

Just for the sake of completeness, you may want to add the official help reference: :h E146. This is explained in the flags section, one of the last paragraphs at :h s_flags

为了完整起见,您可能需要添加官方的帮助引用::h E146。这在flags部分中得到了解释,这是h s_flags的最后一段