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

java, terminal, vim

Solution

Vim has modifiers with which you can manipulate filenames. For your use case, the `:r` modifier returns the root, i.e. the file name with the last extension removed:

:!java %:r

See the full list at `:help filename-modifiers`; they also can be combined. Note that for more complex builds, a Java build solution like Ant or Maven is probably more effective; these can also be launched from Vim; even integrated into its `:make` command.

Problem

If I'm coding in cpp, in Vim I can do: ``` !g++ % && ./a.out ``` to quickly compile and run the code. However, if I'm coding in Java, in Vim I can do: ``` !javac % ``` for a quick compilation, but for running the java class, I cannot do: ``` !java % ``` because I need to put the class name only (without the trailing .java suffix) Is there a quick way in VIM to do what I did when I was coding in Cpp? Thanks a lot.

Original source