如何替换vim中的“%”? \% 不起作用
How to replace "%" inside vim? \% doesn't work
我有这样的 c 格式文本:
"%d %d"
我希望将其更改为类似“%l %l”的文本
我在 vim 命令模式下试过:
:%s:\%d:\%l:g
没用。然后我试了:
:%s:%%d:%%l:g
也不行。如何解决?
您不需要转义 %
字符。这些工作之一:
:%s/%d/%l/g
:%s:%d:%l:g
您不仅限于 /
或 :
作为描述字符。来自 vim 的帮助:
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other single-byte character, but not an alphanumeric character,
'\', '"' or '|'. This is useful if you want to include a '/' in the search
pattern or replacement string. Example: >
:s+/+//+
我有这样的 c 格式文本:
"%d %d"
我希望将其更改为类似“%l %l”的文本
我在 vim 命令模式下试过:
:%s:\%d:\%l:g
没用。然后我试了:
:%s:%%d:%%l:g
也不行。如何解决?
您不需要转义 %
字符。这些工作之一:
:%s/%d/%l/g
:%s:%d:%l:g
您不仅限于 /
或 :
作为描述字符。来自 vim 的帮助:
Instead of the '/' which surrounds the pattern and replacement string, you can use any other single-byte character, but not an alphanumeric character, '\', '"' or '|'. This is useful if you want to include a '/' in the search pattern or replacement string. Example: > :s+/+//+