Vim script for automatic function insertion

孤者浪人 提交于 2019-12-08 04:55:32

问题


Say I have a class evilLord declared in the file evil_lair.hh and is implemented in the file evil_lair.cc. Now, I want to add the function bool minionDo(std::string command). Is there any script which will put the declaration and empty function definition in the respective files automatically?

I am using c-support vim-plugin which I find useful. Maybe this can be added as a functionality to this script...


回答1:


The task is not that trivial -- if we want to correctly report the scope of the function. I've already done the work in my :GOTOIMPL (and :MOVEIMPL) command, from my lh-cpp ftplugin suite.




回答2:


Here is a script which will work:

:let lines = ["bool minionDo(std::string command)"]
:e evil_lair.hh
:call append( line('$'), lines )
:wq

:e evil_lair.cc
:call append( line('$'), lines )
:call append( line('$'), "{}" )
:wq


来源:https://stackoverflow.com/questions/8844817/vim-script-for-automatic-function-insertion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!