用 Vim 编程 Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1085146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programming Java with Vim
提问by
I have tested many editors out there, but Vim makes me addictive. I really wish to use Vim in all of my programming. I just tried to start learning the Java programming language and I have a huge book that I'm trying to start to read for that purpose, but the sad thing about it is that I don't have either a Java compiler or a .class file reader (called a JVM I think, but maybe I am just a noob too and I already have them but don't know how they work).
我已经测试了很多编辑器,但 Vim 让我上瘾。我真的希望在我所有的编程中都使用 Vim。我只是尝试开始学习 Java 编程语言,并且我有一本厚厚的书,我正为此目的而开始阅读,但可悲的是我既没有 Java 编译器也没有 .class文件阅读器(我认为称为 JVM,但也许我也只是个菜鸟,我已经有了它们,但不知道它们是如何工作的)。
I do not wish to use another editor than Vim, that is not my purpose. I know that Vim can call external commands to compile and that I might have to enter some stuff in my _vimrc to let him do so (I use Windows Vista, sad, I know) but I have no idea what to look for and I have searched for days. Any Vim-lovers experts around that could give me a hand out? I see that little Vim command called :javac and it pisses me off to know it's not working yet...
我不想使用 Vim 以外的其他编辑器,这不是我的目的。我知道 Vim 可以调用外部命令进行编译,而且我可能必须在我的 _vimrc 中输入一些东西才能让他这样做(我使用 Windows Vista,可悲,我知道)但我不知道要查找什么,我有搜索了几天。周围的任何 Vim 爱好者专家可以帮助我吗?我看到那个叫做 :javac 的小 Vim 命令,它让我生气,知道它还没有工作......
回答by Eugene Yokota
You need Java SE Development Kit (JDK)to develop Java. Download JDK 6 Update 14 from the page. Modify your path to include bin
folder so you can call javac
, the Java compiler and java
command. Another tool you wanna learn is ant, which lets you compile multiple files all at once, run tests, etc.. Also see Configure vi for Java application development.
您需要Java SE Development Kit (JDK)来开发 Java。从页面下载 JDK 6 Update 14。修改您的路径以包含bin
文件夹,以便您可以调用javac
Java 编译器和java
命令。您想学习的另一个工具是ant,它可以让您一次编译多个文件、运行测试等。另请参阅为 Java 应用程序开发配置 vi。
Edit: Adding link to What are the necessary environment variables one should set after installing JDK on Windows and how?
回答by schubySteve
you are going to need to get the Java Development Kit (JDK) which has the compiler etc, without that the javac command is not going to work.
您将需要获得具有编译器等的 Java 开发工具包 (JDK),否则 javac 命令将无法工作。
回答by oscarkuo
回答by Ratzkewatzke
As eed3si9n points out, you will need the JDK in order to start compiling your Java programs. But your question seems to be more about setting up your editor so that you can automatically compile Java programs from within it.
正如 eed3si9n 指出的那样,您将需要 JDK 才能开始编译您的 Java 程序。但是您的问题似乎更多地是关于设置编辑器,以便您可以从其中自动编译 Java 程序。
There are a couple of ways to approach this, of course. The easiest way is to work out a single command to build the project. In Java, most large projects are compiled with ant, and learning how to use that will serve you very well in the long term.
当然,有几种方法可以解决这个问题。最简单的方法是制定一个命令来构建项目。在 Java 中,大多数大型项目都是用 ant 编译的,从长远来看,学习如何使用它会非常有用。
Once you've set up ant (http://ant.apache.org/manual/install.htmlto start), you can set vi to automatically call it via the ":make" command, by putting in your _vimrc file:
一旦你设置了 ant(从http://ant.apache.org/manual/install.html开始),你可以设置 vi 以通过 ":make" 命令自动调用它,通过放入你的 _vimrc 文件:
set makeprg=C:\path-to-ant\ant
设置 makeprg=C:\path-to-ant\ant
So the steps should be:
所以步骤应该是:
(1) Get the JDK and learn how to use that.
(1) 获取 JDK 并学习如何使用它。
(2) Get ant and learn how to use that. (*)
(2) 获取 ant 并学习如何使用它。(*)
(3) Set your vimrc up so that it knows to invoke ant when you type :make.
(3) 设置您的 vimrc,使其知道在您键入 :make 时调用 ant。
As always, setting up a system to automate something (like your compiles) is easier when you're already proficient at doing it manually.
与往常一样,当您已经精通手动操作时,设置系统来自动执行某些操作(例如您的编译)会更容易。
(*) Note: My vim doesn't have the javac command, so I'm not sure how to configure the vim options necessary to make sure you load it. If nothing else, it would be good to make sure that your javac was in your PATH at the time you load the editor.
(*) 注意:我的 vim 没有 javac 命令,所以我不确定如何配置确保加载它所需的 vim 选项。如果不出意外,最好确保在加载编辑器时 javac 位于 PATH 中。
Best wishes!
最好的祝愿!
回答by adrian.tarau
Using Vim to write complex Java applications is a nice dream, but it's gonna be a short one :) I know you must be used with VIM(which is fine) but why not using a modern IDE to write a Java application? Most of the current IDEs allows to change the keyboard mapping, so you could bring VIM to your IDE editor...
使用 Vim 编写复杂的 Java 应用程序是一个美好的梦想,但它会很短:) 我知道您必须使用 VIM(这很好),但为什么不使用现代 IDE 编写 Java 应用程序呢?当前的大多数 IDE 都允许更改键盘映射,因此您可以将 VIM 带入您的 IDE 编辑器...
A few years ago we had a new employee which had a similar dream...after one month he left, I think he realized changing an application with 0.5mil LOC cannot be done in Vim.
几年前,我们有一个有类似梦想的新员工……他离开一个月后,我想他意识到在 Vim 中无法更改 50 万行 LOC 的应用程序。
Just my $0.02.
只是我的 0.02 美元。
回答by Brian Agnew
Can I suggest that you use a decent IDE, anda VIM plugin? I used to be a VIM diehard, and only recently switched to using Eclipse with a VIM editor plugin.
我可以建议您使用像样的 IDE和VIM 插件吗?我曾经是 VIM 的死忠粉,直到最近才改用带有 VIM 编辑器插件的 Eclipse。
Why? The productivity gains of using a modern IDE are enormous. For example, once you're able to navigate through the code by structure type (e.g. method call to list of implementations etc.) then the ctags
mechanism in VIM just isn't enough. Once you use more than a couple of libraries (or stuff you're not familiar with) then the code completion / method suggestion / doc navigation will save you a world of grief.
为什么?使用现代 IDE 的生产力提升是巨大的。例如,一旦您能够按结构类型(例如方法调用到实现列表等)浏览代码,那么ctags
VIM 中的机制就不够了。一旦您使用了多个库(或您不熟悉的东西),那么代码完成/方法建议/文档导航将为您节省一个悲伤的世界。
However I love the VIM method of keyboard navigation etc. Hence I use an IDE with an appropriate plugin.
但是我喜欢键盘导航等的 VIM 方法。因此我使用带有适当插件的 IDE。
Here's an answerI provided to a very similar question. That contains the link to the Eclipse VIM plugin. It's not free, but will pay for itself very quickly.
这是我为一个非常相似的问题提供的答案。其中包含指向 Eclipse VIM 插件的链接。它不是免费的,但会很快收回成本。
回答by stephan f
There's a great vim plugin JavaRunthat covers the basics of compiling and running, as well as having abbreviations for common code bits that save typing. Just drop it into %HOME%\vimfiles\plugin on Windows.
有一个很棒的 vim 插件JavaRun,它涵盖了编译和运行的基础知识,以及用于节省输入的常用代码位的缩写。只需将其放入 Windows 上的 %HOME%\vimfiles\plugin 即可。