This configuration script enables automatic generation of a basic Java class structure for use in Vim or NeoVim. I got tired of having to manually type out classes during development, so I got to work productively procrastinating and this was the result. Whenever you create a new .java file with Vim, the package declaration, class definition, and a main method are generated. The class and package names are inferred from the file's name and location within a standard Java project structure (based on Maven and Gradle).
Features:
- Automatic: when this script is in your .vimrc, generation is automatic
- Dynamic: the public class name is auto-matched to the filename
- Smart: package declarations are auto-generated by analyzing the file's path relative to the project root
- Javadoc: includes a basic Javadoc that can easily be updated
- Modular: this template is easy to update via the vimrc. More info below
No additional plugins are required for this as it is written in pure Vimscript. Just clone the repo (or copy and paste) and add the code to your ~/.vimrc or init.vim file.
- Save your Vim configuration: Ensure the code above is saved in your ~/.vimrc or init.vim
- Restart Vim
- Create a new Java file: either vim test.java or :e path/to/your/package/MyClass.java
- If the file is actually new, the boilerplate will be automatically inserted and your cursor will be placed inside the class.
Author Name: Change "Your Name" in the call add(boilerplate, ' * @author Your Name') to your name
Boilerplate content: you can easily add or remove lines from the list within the JavaBoilerPlate() function to customize what is generated.
Feel free to make suggestions via a pull request, or fork this repo and put your own spin on it.