If you can define it all in one substitute
all then replace the escape
, since that can be any function. <C-R>=substitute(@s, '\m\(\w\+\) \w\+::\([^{]\+\) {', '\1 \2;', '')<CR>
If you don't want to do it all in one substitute
, or to give it a descriptive name, you can write your own function.
For example:
function! FunctionDeclaration(snip)
return substitute(a:snip, '\m\(\w\+\) \w\+::\([^{]\+\) {', '\1 \2;', '')
endfunction
Then invoke it with <C-R>=FunctionDeclaration(@s)<CR>
See :help user-functions
for defining your own function like FunctionDeclaration
above.
See :help substitute()
for how to perform a regex substitution against a variable.
The breakdown of the regex suggested above:
\m
- Enable magic
so that the regex behavior is not impacted by user settings. See :help magic
.
\(\w\+\)
- Match a series of one or more "word characters". Matches the void
in the example. See :help \w
. Capture the result of that part of the match into the first match group. See :help pattern-overview
. This can be referenced with \1
in the replacement.
\w\+::
- Match a series of one or more "word characters" followed by ::
. This matches the MyClass::
in the example. This is not matched in a subgroup so it will be dropped in the replacement.
\([^{]+\)
- Match a series of characters which are not {
in a subgroup. This matches the foo()
in the example. Can be reference by \2
in the replacement.
{
- Match the literal {
at the end. Not matched in a subgroup
so it is dropped.
lh#cpp#AnalysisLib_Function#AnalysePrototype('void MyClass::foo(int)')
(from my lh-cpp) will return{'throw':[], 'parameters': [{'nl':0, 'name':'', 'type':'int', 'default':''}], 'constexpr':0, 'name':['MyClass', 'foo'], 'noexcept':'', 'const':0, 'return':'void', 'pure':0, 'qualifier':'', 'overriden':0, 'volatile':0, 'final':0, 'special_definition':''}
. From there you'll be able to reconstruct the declaration from the definition -- I usually use it the other way with:GOTOIMPL
(virtual & co cannot be deduced from the definition)