要做一个正确的重构,你必须有很多关于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的文档并不表明它提供了一个提取方法功能。