重构C / C ++中的Vim(例如方法提取就像在Eclipse) [英] Refactoring C/C++ in Vim (e.g. method extraction like in Eclipse)

查看:161
本文介绍了重构C / C ++中的Vim(例如方法提取就像在Eclipse)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有Vim的像在Eclipse?

Are there any plugins or built-in methods in Vim for performing refactoring on C or C++ code, something like the refactoring tools in Eclipse?

我在Eclipse中的提取方法重构工具特别热衷,将决定新方法的参数,通常也猜一个变量作为返回值来使用。

I'm especially keen on the extract method refactoring tool from Eclipse that will determine parameters from new methods and typically also guess a variable to use as the return value.

推荐答案

没有,尽管Vim编辑一个良好的环境,并可以在很多方面定制(code折叠,语法着色,宏扩展等)。大多数的这些的语法水平完成,而不是在语义层次。即使是code折叠只是相匹配反对括号。

No, although Vim is a good environment for editing, and can be customised in a lot of ways (code folding, syntax colouring, macro expansion etc.) most of these are done on the syntax level, rather than the semantic level. Even the code folding just matches up opposing braces.

做一个适当的重构,你必须有很多关于AST语义知识,在这种范围内声明的变量是什么,等等。如Eclipse的IDE建立在每一个词法范围定义的变量的高速缓存,使他们能快速查阅到他们确定哪些重命名和地点方面使用。

To do a proper refactoring, you have to have a lot of semantic knowledge about the AST, what variables are declared in which scope, and so on. IDEs like Eclipse build up a cache of the variables defined in each lexical scope, so that they can quickly refer back to where they are used in terms of determining what to rename and where.

这并不是说你不能做一些事情语法;毕竟,人们只需拿出code块,放入一个单独的函数很轻松了。你甚至可以在一些参数猜测(如找到变量列表,找出哪些有局部声明,删除它们,还剩下些什么是你的参数,但Eclipse还做其他的事情—像搞清楚任何变量是否修改了功能,并确保他们的返回值传递回来。它还检查任何抛出的异常,并把它们添加到列表中。

That's not to say that you can't do some things syntactically; after all, one can just take out a block of code and put it into a separate function easily enough. You might even be able to guess at some parameters (e.g. find a list of the variables, find out which ones have local declarations, remove them and what's left are your parameters. But Eclipse also does other things—like figuring out whether any variables are modified in the function, and ensuring they're passed back by the return value. It also checks for any thrown exceptions, and add them to the list.

最终的结果是,虽然你可以近似其中的一些在Vim中,你真的不打算能够在一个只有VIM-enviornment得到这个工作。你既可以使用一个Vim样键绑定在Eclipse正确,或看 eclim 。从主页:

The net effect is that whilst you may be able to approximate some of these in Vim, you really aren't going to be able to get this working in a Vim-only enviornment. You could either use a Vim-like keybinding in Eclipse proper, or look at eclim. From the home page:

eclim的主要目标是使
  Eclipse功能外Vim的
  编辑。最初的目标是
  提供Eclipse的Java功能
  在vim,但由于种种其他支持
  语言(C / C ++,PHP,Python和Ruby,
  CSS,HTML,XML等)已添加
  还有几个正在规划中。

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少一个应用程序的和
  以上两个伟大的整合
  项目。首先,Vim的,可以说是
  最好的文本编辑器中的一个
  存在。第二,Eclipse中,
  提供了许多伟大的工具
  发展各种语言。每
  提供了许多功能,可以
  提高开发人员的生产力,但
  双方仍留下遗憾的地方
  期望。 Vim的缺乏原生Java支持
  和许多的高级功能
  在Eclipse中使用。 Eclipse中,在
  另一方面,仍然需要使用
  鼠标的很多事情,当
  相比Vim的,提供了一个小于
  编辑文本理想的接口。

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.

这就是eclim用武之地。
  而不是试图写一个IDE中
  VIM或在Eclipse中Vim编辑器,eclim
  提供了一个Eclipse插件,
  通过公开的Eclipse功能
  服务器接口,和一组的Vim
  插件,与Eclipse沟通
  通过该接口。

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中。但是,你仍然可以获得VIM的导航和文本编辑功能。这听起来像这可能满足您的需求,虽然重构支持文档并不表示它提供了一个摘录方法的功能。

This not only gives an Eclipse-like environment, it is Eclipse. But you still get the navigation and text editing features of vim. It sounds like this might suit your needs, although the documentation on refactoring support doesn't indicate that it provides an extract method functionality.

这篇关于重构C / C ++中的Vim(例如方法提取就像在Eclipse)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆