pcd13
pcd13

Reputation: 51

How to display code output in current gvim window?

I'm (slowly) teaching myself how to program, and I'm using gVim as my text editor. So, I have a question, that I was wondering if gVim has this feature. So, lets say I am writing Hello World in Java.

I can write the program in vim, hit esc, then type (using my pattern matching skills):

:!javac %

(this will open up a vimrun window, compile the code and list any errors)

then:

:!java hello (or whatever the class is named)

Then a new window pops up and displays the output of the code. So what I want to do is display any compilation errors, then the output, in the current vim window, without opening a new window. So I would like, if possible, to display the code (for lack of knowledge of the correct term) among the blue squiggles. After extensive googling, the closest I could find to what I want is

:read !java hello

and that will paste the output below the code. But this is not quite what I want. So is it possible to display any compilation errors, and code output, specifically where I'd like it?

Thanks again

Upvotes: 2

Views: 206

Answers (1)

Amadan
Amadan

Reputation: 198324

The easiest is to use Apache Ant (Java build tool, Java's equivalent of make). From here:

Add the following lines in your .vimrc:

autocmd BufRead *.java set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
autocmd BufRead set makeprg=ant\ -find\ build.xml

Then make a build.xml file for your project, and you can then do :make (or :make run, or any other target) to run Ant on the appropriate target. How to build the build.xml is a bit outside the scope of the question, but you can follow the Ant Hello World tutorial, which should be enough to get you started.

The :make command will execute the make tool (in this case, Ant), and put the output into a special window in Vim. In case of compiler output, you might also be able to press Enter on a line to jump to the appropriate line of code. (Not sure, I don't remember doing it with Java).

Another way to go about this is to use the ConqueShell plugin, which allows you to run and interact with terminal programs in a Vim window.

Upvotes: 2

Related Questions