简体   繁体   English

vim替换反斜杠

[英]vim substitute backslash

I am trying to extract only the function name from a function declaration using vim script. 我试图使用vim脚本从函数声明中仅提取函数名称。 For testing purposes I am using this simple example: 出于测试目的,我使用这个简单的例子:

int func(int a);

In vim script I am extracting the function name by this: 在vim脚本中,我通过这个提取函数名:

:let a = substitute(getline(line('.')), ".*\(func\).*", "\1", "")

But the backreference is not working. 但反向引用不起作用。 When I echo the variable a with 当我回显变量a时

:echo a

it displays the whole line, ie int func(int a); 它显示整行,即int func(int a);

How to extract only the function name with bacreference or any other method? 如何使用bacreference或任何其他方法仅提取函数名称?

Thanks in advance! 提前致谢!

Inside double quotes, backslashes must be escaped. 在双引号内,必须转义反斜杠。 Either use single quotes ( '\\1' ) or double all backslashes ( "\\\\1" ). 使用单引号( '\\1' )或双倍所有反斜杠( "\\\\1" )。

See :help expr-string for details. 有关详细信息,请参阅:help expr-string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM