我正在尝试使用 vim submatch 命令在一行文本中的所有字符串周围加上引号,但它不起作用。这是我在做什么
:s:\a*\a:\(submatch(0)\):g
Run Code Online (Sandbox Code Playgroud)
它所做的只是用字符串 (submatch(0)) 替换所有字符串。我如何让 vim 做我想做的事?
小智 6
submatch 不是执行此操作的最佳解决方案。我正在做一些 helpgrep\\=
我发现这个:
*sub-replace-special* *:s\=*
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|. You can use that for any special characters.
Otherwise these characters in {string} have a special meaning:
Run Code Online (Sandbox Code Playgroud)
如果你坚持使用 submatch 你可以这样使用它:
s:\a*\a:\='"'.submatch(0).'"'
Run Code Online (Sandbox Code Playgroud)
然而,一个更具可读性的解决方案是:
s:\a*\a:"\0"
Run Code Online (Sandbox Code Playgroud)