3

I am trying to extract only the function name from a function declaration using vim script. For testing purposes I am using this simple example:

int func(int a);

In vim script I am extracting the function name by this:

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

But the backreference is not working. When I echo the variable a with

:echo a

it displays the whole line, i.e. int func(int a);

How to extract only the function name with bacreference or any other method?

Thanks in advance!

4

1 に答える 1

8

Inside double quotes, backslashes must be escaped. Either use single quotes ('\1') or double all backslashes ("\\1").

See :help expr-string for details.

于 2012-12-28T11:45:33.837 に答える