The original intention is to implement a Vim plug-in, be able to automate the implementation of the method declared in H-header files in C + + into the CPP implementation file (the C.vim I know is not implemented as I meant, implemented well in the source menu in Eclipse), using the line that needs to parse the current cursor, such as:
Need to be
void SayHello (int msg,string buffer);
Converted to
void Hello::sayhello (int msg,string msg2) {
}
Must parse out the return value function name, the parameter and so on, uses the VIM built-in function to be possible to solve, because the regular expression and the general wording is slightly different, has made the memo, for instance
() need to add days add \ \ (\)
[] No
{} needs to be written as \{\}
? need to write \?
Matchlist (' Hello World (int msg,string msg2) ', ' (. *\) \s\+\ (. *\) \s* (\ (. *\))
This function returns a list
[' Hello World (int msg,string msg2); ', ' Hello ', ' world ', ' int msg,string msg2 ', ', ', ', ', ', ', ', ', ', ', ', '
You can resolve the return list to continue.
The complete plugin is as follows (need to install switch header file and implement file plugin A.vim)
if exists("loaded_generate_impl_corey")
finish
endif
let loaded_generate_impl_corey=1
function <SID>GetClassName(lineNum)
let tmplinenum=a:lineNum
while tmplinenum>0
let tmplinenum-=1
let tmpline=getline(tmplinenum)
let clslist=matchlist(tmpline,'\s*class\s*\(\S*\)\s*.*')
if stridx(tmpline,'class ')>=0
return get(clslist,1)
endif
endwhile
return ""
endfunction
function <SID>ToImpl()
let s:curline=getline(line("."))
let s:flist= matchlist(s:curline, '\s*\(.*\)\s\+\(.*\)\s*(\(.*\));')
if strlen(get(s:flist,0))== 0 || strlen(get(s:flist,2))== 0
echo "this is not a function"
return
endif
let s:rtn=get(s:flist,1)
if s:rtn=='virtual'
let s:rtn=""
endif
let s:method=get(s:flist,2)
let s:args=get(s:flist,3)
let s:classname=<SID>GetClassName(line("."))
let s:implclause="\n\t".s:rtn . (strlen(s:rtn)==0?"":" ") .s:classname."::". s:method . "(". s:args . ")" . "{" . "\n" ."\n"."\t"."}"
call setreg('',s:implclause)
execute ":A"
execute "normal G"
execute "normal p"
call cursor(line(".")+2,0)
endfunction
nnoremap zz :call <SID>ToImpl()<CR>