sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

copycppdectoimp.vim : Expanded version of VIM-TIP#335 - Copy C++ function declaration into implementat

 script karma  Rating 35/13, Downloaded by 2286    Comments, bugs, improvements  Vim wiki

created by
Robert KellyIV
script type
Ment for cpp class member functions, also works for normal c functions; modify for others...
This is not perfect, but works pretty good. -- Works out of the box, however you may want to customize it some. Customization is as easy as defining some global vars...

" OPTIOINAL: Place something like the below in your .vimrc or where ever you like to keep your global option vars and change as desired.
" Note, these are the defaults.
" GHPH Options: {{{
" See copycppdectoimp.vim for more documtation.
" Virtual: 1 for commented, else removed.
let g:ghph_ShowVirtual                    = 0
" Static:  1 for commented, else removed.
let g:ghph_ShowStatic                     = 0
" Default Params: 3 for /*5*/, 2 for /* = 5*/, else removed.
let g:ghph_ShowDefaultParams     = 3
" Command: 1 to define :GHPH (default if nothing defined), 0 to NOT define.
let g:ghph_useGHPH                       = 1
" Command: 1 to define :GH and :PH, 0 to NOT define.
"let g:ghph_useGHandPH               = 1
" }}}

:GHPH when in a header file (.h) and on a member function decloration.
Then :GHPH when in a source file (.cpp or the like) where you want the properly expanded implimentation of the member function.
(There is also :GH and :PH or :GHPH g :GHPH p as alternitive methods of using this, see below.)

Please see the comments in the file for more info.

class CTest
    void Test_Member_Function_G(
        int        _iSomeNumber,                //!< doxy comment
        char    * _cpSomeString,            //!< Same
        float    /*_fNotused*/,        //!< not used param. Heh aka error stress test.
        int        _iFlags = 0            /*!< I think */
        );    // yea whatever.
// nested classes/structs and inlined functions supported.
// If you have something you want to work but doesnt email me an I'll see if I can get it to.

Place cursor on line with 'Test_Member_Function_G' and :GHPH
Place cursor in .cpp file where you want function and :GHPH gives you:
void CTest::Test_Member_Function_G(int _iSomeNumber, char * _cpSomeString, float /*_fNotused*/, int _iFlags/*0*/)
With your cursor on the opening brace ready for a o

How static, virtual and default params are comented in the function are configurable (can totally remove them if you like), See the file for more info.

Note that you call :GHPH twice (I was playing with this idea--one less thing to remember) The function decides what to do based on the file extension (only .h at the moment but easy to change/add more). If you like it is as easy as unreming the command definitions to get :GH and :PH.

You can overide :GHPH's attempt to be clever and force getting the definition or putting the implimentation via :GHPH g and :GHPH p respectivly.

Although still a work in progress it both functions and behaves well.

To TRY this all you need to is place this in your ftplugin/cpp directory and then :GHPH on a member function and :GHPH in the source file. Don't like it? remove the file from ftplugin/cpp

Thanks to Leif Wickland for VIM-Tip#335 from which this file derived.
See: http://vim.sourceforge.net/tip_view.php?tip_id=335

What YOU would like to see in this script wanted, drop me an email.
Happy VIMing!
install details
Drop in your ftplugin/cpp directory.

Uninstall is just remove the script file and any vars/mappings you have made.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
copycppdectoimp.vim 0.46 2003-06-03 6.0 Robert KellyIV Refined matching declaration prens; should be more resistant to mismatched prens outside of the function declaration. Mismatched prens inside the function declaration (i.e. in comments) will confuse this still.
NOTE that I goofed the previous version's number, it was 0.45 NOT 0.55. Oopsie!
copycppdectoimp.vim 0.55 2003-05-04 6.0 Robert KellyIV * Bug fix: more robust handling of comments and prens and things in multi line function declorations.
* Small fix to take into account non blank equalprg; thanks to Nathan Dunn for help tracking this down.
copycppdectoimp.vim 0.43 2002-10-17 6.0 Robert KellyIV Bugfix, The case of filename extension no loger matters during the check for header/source.
copycppdectoimp.vim 0.32 2002-10-09 6.0 Robert KellyIV * More intelligent/robust checking/finding the class.
* Nested classes are now supported.
* Normal functions now work.
copycppdectoimp.vim 0.3 2002-10-07 6.0 Robert KellyIV Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo