在Vim中重构C/C(例如像Eclipse中的方法提取)

Vim中是否有任何插件或内置方法用于对C或C代码执行重构,类似于Eclipse中的重构工具?

我特别热衷于Eclipse中的提取方法重构工具,它将从新方法确定参数,通常也猜测一个变量用作返回值。

不,虽然Vim是一个良好的编辑环境,并且可以以很多方式(代码折叠,语法着色,宏扩展等)来定制,大多数是在语法级别而不是语义级别上完成的。甚至代码折叠只是匹配相反的大括号。

要做一个正确的重构,你必须有很多关于AST的语义知识,什么变量在什么范围内被声明,等等。类似Eclipse的IDE构建了一个在每个词法作用域中定义的变量的缓存,以便他们可以快速参考它们在确定重命名和位置方面的使用。

这不是说你不能在语法上做一些事情;毕竟,可以只取出一个代码块,并把它放到一个单独的函数足够容易。你甚至可以猜到一些参数(例如,找到一个变量列表,找出哪些有局部声明,删除它们,剩下的是你的参数,但Eclipse也做了其他事情,比如判断任何变量是否在函数中修改,并确保它们被返回值返回,它还检查任何抛出的异常,并将它们添加到列表中。

净效果是,虽然你可能能够在Vim中估计一些这些,你真的不能在一个Vim-only环境中工作。您可以在Eclipse中使用类似Vim的键绑定,或者查看eclim.从主页:

The primary goal of eclim is to bring
Eclipse functionality to the Vim
editor. The initial goal was to
provide Eclipse’s java functionality
in vim,but support for various other
languages (c/c++,php,python,ruby,
css,html,xml,etc.) have been added
and several more are planned.

Eclim is less of an application and
more of an integration of two great
projects. The first,Vim,is arguably
one of the best text editors in
existence. The second,Eclipse,
provides many great tools for
development in various languages. Each
provides many features that can
increase developer productivity,but
both still leave something to be
desired. Vim lacks native Java support
and many of the advanced features
available in Eclipse. Eclipse,on the
other hand,still requires the use of
the mouse for many things,and when
compared to Vim,provides a less than
ideal interface for editing text.

That is where eclim comes into play.
Instead of trying to write an IDE in
Vim or a Vim editor in Eclipse,eclim
provides an Eclipse plug-in that
exposes Eclipse features through a
server interface,and a set of Vim
plug-ins that communicate with Eclipse
over that interface.

这不仅给出了一个类似Eclipse的环境,它是Eclipse。但你仍然得到vim的导航和文本编辑功能。听起来这可能适合你的需要,虽然refactoring support的文档并不表明它提供了一个提取方法功能。

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...