0

Normally you would compile java using this:

javac Hello.java
java Hello

Under certain conditions you can compile from Vim by just typing :make by placing this in .vimrc

autocmd Filetype java set makeprg=java\ %

Recently it hasn't been working though.

I've figured out that the path is the problem. How do I include it in my vimrc? I'm not sure exactly what the semantics behind that would be.

1
  • 1
    Welcome (back) to Vi and Vim! Can you please edit to explain it doesn't work? (PS the only reason java % would work is the relatively new "java as scripts" thing where you don't have to compile single-file programs ahead-of-time. In more complicated projects that simply won't work.) – D. Ben Knoble Feb 11 at 17:49
1

To compile with javac filename.java, then use javac %. (+the backslash)

If you want to execute java filename without the extension, then use java %< .

Note, there is exists a :compiler javac that also change the 'errorformat' option, but it won't inject the current filename, you'd have to compile with :make %

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.