Tip #335: Copy C++ function declaration into implementation file
tip karma |
Rating 8/5, Viewed by 1047
|
created: |
|
October 1, 2002 6:47 |
|
complexity: |
|
basic |
author: |
|
Leif Wickland |
|
as of Vim: |
|
5.7 |
There's a handy plug in for MS Visual Studio called CodeWiz that has a nifty ability to copy a function declaration and deposit it into the implementation file on command. I actually missed while using vim, so I wrote an approximation of that capability. This isn't foolproof, but it works alright.
" Copy Function Declaration from a header file into the implementation file.
nmap <F5> "lYml[[kw"cye'l
nmap <F6> ma:let @n=@/<cr>"lp==:s/\<virtual\>/\/\*&\*\//e<cr>:s/\<static\>/\/\*&\*\//e<cr>:s/\s*=\s*0\s*//e<cr>:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:let @/=@n<cr>'ajf(b"cPa::<esc>f;s<cr>{<cr>}<cr><esc>kk
To use this, source it into vim, for example by placing it in your vimrc, press F5 in normal mode with the cursor on the line in the header file that declares the function you wish to copy. Then go to your implementation file and hit F6 in normal mode with the cursor where you want the function implementation inserted.
<<Loading scripts in .vimrc safely |
type the line number and press enter to get there >>
Additional Notes
|