The easiest way to run a java class when editing a .java VIM form file

If I code in cpp, in Vim I can do:

!g++ % && ./a.out

to quickly compile and run code.

However, if I code in Java, in Vim I can do:

!javac %

for quick compilation, but to run the java class I cannot:

!java %

because I need to put only the class name (without the suffix .java)

Is there a quick way in VIM to do what I did when I encoded in Cpp?

Many thanks.

+5
source share
1 answer

Vim has modifiers with which you can manipulate file names. For your use case, the modifier :rreturns the root, that is, the name of the file with the last extension removed:

:!java %:r

. :help filename-modifiers; . , Java build, Ant Maven, , ; Vim; :make.

+6

All Articles