https://github.com/alessio-vivaldelli/java-creator-nvim
Neovim plugin for generating Java files (classes, interfaces, enums, records) with package-aware autocompletion.
https://github.com/alessio-vivaldelli/java-creator-nvim
java nvim plugin
Last synced: 3 months ago
JSON representation
Neovim plugin for generating Java files (classes, interfaces, enums, records) with package-aware autocompletion.
- Host: GitHub
- URL: https://github.com/alessio-vivaldelli/java-creator-nvim
- Owner: alessio-vivaldelli
- License: mit
- Created: 2025-08-13T14:04:55.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2026-02-07T16:08:57.000Z (3 months ago)
- Last Synced: 2026-02-08T00:49:19.515Z (3 months ago)
- Topics: java, nvim, plugin
- Language: Lua
- Homepage:
- Size: 1.09 MB
- Stars: 17
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim-sorted - alessio-vivaldelli/java-creator-nvim - aware autocompletion. | (Programming Languages Support)
- awesome-neovim - alessio-vivaldelli/java-creator-nvim - Interactive Java file creator with automatic package detection, supporting classes, interfaces, enums, records and abstract classes. (Programming Languages Support / Diagnostics)
README
# java-creator.nvim
- [java-creator.nvim](#java-creatornvim)
- [Features](#features)
- [Demo](#demo)
- [Create new class inside an existing package](#create-new-class-inside-an-existing-package)
- [Create new class inside a new package](#create-new-class-inside-a-new-package)
- [Installation](#installation)
- [Usage](#usage)
- [Basic Commands](#basic-commands)
- [Configuration](#configuration)
This plugin was created to help generate Java class files like in different IDEs, in an interactive way that allows you to choose which package to place it in and to create a new one if needed. When creating the file, it automatically sets the file's package so you don't have to do it manually.
## Features
- Supports:
- Classes
- Interfaces
- Enums
- Records (Java 16+)
- Abstract classes
- Automatic package detection
- Check file/package name validity
## Demo
### Create new class inside an existing package

### Create new class inside a new package

## Installation
Using [Lazy.nvim](https://github.com/folke/lazy.nvim), with basic configuration:
```lua
{
'alessio-vivaldelli/java-creator-nvim',
ft = 'java',
opts = {
-- Default configuration
keymaps = {
java_new = "jn",
},
options = {
auto_open = true, -- Open file after creation
java_version = 17 -- Minimum Java version
}
}
}
```
Suggested configuration is:
```lua
{
{
"alessio-vivaldelli/java-creator-nvim",
config = function()
require("java-creator-nvim").setup({
options = {
java_version = 17,
auto_open = true,
use_notify = true,
custom_src_path = "backend/src/main/java",
src_patterns = { "src/main/java", "src/test/java", "src" },
project_markers = { "pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts", ".project" },
notification_timeout = 3000,
},
keymaps = {
java_new = "jn",
java_class = "jc",
java_interface = "ji",
java_enum = "je",
java_record = "jr",
},
default_imports = {
record = { "java.util.*" }, -- Import di default per i record
},
})
vim.keymap.set("i", "", 'pumvisible() ? "\\" : "\\\\"', {
expr = true,
desc = "",
})
end,
ft = "java",
event = "VeryLazy",
dependencies = {
{ "rcarriga/nvim-notify", optional = true },
},
},
}
```
## Usage
### Basic Commands
```vim
:JavaNew " Interactive creation wizard
:JavaClass " Create a new class
:JavaInterface " Create a new interface
:JavaEnum " Create a new enum
:JavaRecord " Create a new record (Java 16+)
:JavaAbstractClass " Create a new abstract class
```
You can also set keymaps to bind this operation.
## Configuration
All configuration are:
```lua
-- Customize templates for Java types
templates = {
class = [[package %s;
public class %s {
// TODO: Implement class
}]],
interface = [[package %s;
public interface %s {
// TODO: Implement interface
}]],
enum = [[package %s;
public enum %s {
// TODO: Add enum values
}]],
record = [[package %s;
public record %s() {
// TODO: Add record components
}]],
abstract_class = [[package %s;
public abstract class %s {
// TODO: Implement abstract class
}]],
},
-- Default imports for each type
default_imports = {
record = { "java.util.*", "java.io.Serializable" },
class = { "java.util.*" },
},
-- Custom key mappings
keymaps = {
java_new = "jn", -- Interactive Java file creation
java_class = "jc", -- Create new class
java_interface = "ji", -- Create new interface
java_enum = "je", -- Create new enum
java_record = "jr", -- Create new record
java_abstract_class = "ja", -- Create new abstract class
},
-- General options
options = {
auto_open = true, -- Automatically open created file
use_notify = true, -- Use notifications (nvim-notify if available)
notification_timeout = 3000, -- Notification timeout in milliseconds
java_version = 17, -- Target Java version
src_patterns = { -- Patterns to find source directories
"src/main/java",
"src/test/java",
"src"
},
project_markers = { -- Files that identify a Java project
"pom.xml",
"build.gradle",
"build.gradle.kts",
"settings.gradle",
"settings.gradle.kts",
".project"
},
custom_src_path = nil, -- Custom source path (optional)
```
- **Templates**: Customize the initial content for different Java file types.
- **Default Imports**: Specify automatic imports for each file type.
- **Keymaps**: Customize keyboard shortcuts for quick file creation.
- **Options**:
- `auto_open`: If true, automatically opens the created file.
- `use_notify`: Shows notifications using nvim-notify or falls back to vim.notify.
- `java_version`: Sets the target Java version (affects feature availability like records).
- `src_patterns`: Directories where Java source files are searched.
- `project_markers`: Files/directories that identify a Java project root.