Skip to content

Nhogg/Vim-Auto-Class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Auto-Generate Class Boilerplates

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

Installation and Configuration

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.

Usage

  1. Save your Vim configuration: Ensure the code above is saved in your ~/.vimrc or init.vim
  2. Restart Vim
  3. Create a new Java file: either vim test.java or :e path/to/your/package/MyClass.java
  4. If the file is actually new, the boilerplate will be automatically inserted and your cursor will be placed inside the class.

Customization:

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.

Contribution

Feel free to make suggestions via a pull request, or fork this repo and put your own spin on it.

About

Automatically generate Java class structure in Vim.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors