要做一个正确的重构,你必须有很多关于AST的语义知识,什么变量在什么范围内被声明,等等。类似Eclipse的IDE构建了一个在每个词法作用域中定义的变量的缓存,以便他们可以快速参考它们在确定重命名和位置方面的使用。
这不是说你不能在语法上做一些事情;毕竟,可以只取出一个代码块,并把它放到一个单独的函数足够容易。你甚至可以猜到一些参数(例如,找到一个变量列表,找出哪些有局部声明,删除它们,剩下的是你的参数,但Eclipse也做了其他事情,比如判断任何变量是否在函数中修改,并确保它们被返回值返回,它还检查任何抛出的异常,并将它们添加到列表中。
净效果是,虽然你可能能够在Vim中估计一些这些,你真的不能在一个Vim-only环境中工作。您可以在Eclipse中使用类似Vim的键绑定,或者查看eclim.从主页:
The primary goal of eclim is to bring@H_403_15@ Eclipse functionality to the Vim@H_403_15@ editor. The initial goal was to@H_403_15@ provide Eclipse’s java functionality@H_403_15@ in vim,but support for varIoUs other@H_403_15@ languages (c/c++,PHP,python,ruby,@H_403_15@ css,html,xml,etc.) have been added@H_403_15@ and several more are planned.
Eclim is less of an application and@H_403_15@ more of an integration of two great@H_403_15@ projects. The first,Vim,is arguably@H_403_15@ one of the best text editors in@H_403_15@ existence. The second,Eclipse,@H_403_15@ provides many great tools for@H_403_15@ development in varIoUs languages. Each@H_403_15@ provides many features that can@H_403_15@ increase developer productivity,but@H_403_15@ both still leave something to be@H_403_15@ desired. Vim lacks native Java support@H_403_15@ and many of the advanced features@H_403_15@ available in Eclipse. Eclipse,on the@H_403_15@ other hand,still requires the use of@H_403_15@ the mouse for many things,and when@H_403_15@ compared to Vim,provides a less than@H_403_15@ ideal interface for editing text.
That is where eclim comes into play.@H_403_15@ Instead of trying to write an IDE in@H_403_15@ Vim or a Vim editor in Eclipse,eclim@H_403_15@ provides an Eclipse plug-in that@H_403_15@ exposes Eclipse features through a@H_403_15@ server interface,and a set of Vim@H_403_15@ plug-ins that communicate with Eclipse@H_403_15@ over that interface.
这不仅给出了一个类似Eclipse的环境,它是Eclipse。但你仍然得到vim的导航和文本编辑功能。听起来这可能适合你的需要,虽然refactoring support的文档并不表明它提供了一个提取方法功能。