Skip to content

A Neovim plugin that detects multiple FROM instructions in Dockerfiles and automatically adds separator lines to improve readability of multi-stage builds.

Notifications You must be signed in to change notification settings

mingming-cn/dockerfile-enhance.nvim

Repository files navigation

dockerfile-enhance.nvim

A Neovim plugin that detects multiple FROM instructions in Dockerfiles and automatically adds separator lines to improve readability of multi-stage builds.

中文版本: README.md

Features

  • 🔍 Automatically detects multiple FROM instructions in Dockerfiles
  • 📏 Adds configurable separator lines between multiple FROM instructions
  • 🎨 Supports custom separator characters and lengths
  • 🌈 Highlights separator lines
  • 🔄 Supports adding/removing/toggling separator lines
  • 📊 Shows detailed FROM instruction information
  • ⚡ Auto mode: automatically applies when opening Dockerfile
  • 🎯 Virtual text mode: doesn't modify file content, only shows visual effects
  • 🔧 Debug mode: controls notification display levels

Installation

Using packer.nvim

use {
    'mingming-cn/dockerfile-enhance.nvim',
    config = function()
        require('dockerfile-enhance').setup()
    end
}

Using lazy.nvim

{
    'mingming-cn/dockerfile-enhance.nvim',
    config = true,
    event = { "BufReadPost Dockerfile*", "BufReadPost *.dockerfile", "BufEnter Dockerfile*", "BufEnter *.dockerfile" }
}

Using vim-plug

Plug 'mingming-cn/dockerfile-enhance.nvim'

Configuration

require('dockerfile-enhance').setup({
    separator_char = "",      -- Separator character
    separator_length = 80,     -- Separator length
    highlight_group = "Comment", -- Highlight group
    auto_enhance = true,       -- Whether to auto-enhance
    enable_highlights = true,  -- Whether to enable highlights
    enable_virtual_text = true, -- Whether to enable virtual text (recommended)
    virtual_highlight_group = "Comment", -- Virtual text highlight group
    debug = false,             -- Debug mode (set to true to show all notifications)
})

Configuration Options

Option Type Default Description
separator_char string "─" Separator character
separator_length number 80 Separator length
highlight_group string "Comment" Highlight group name
auto_enhance boolean true Whether to auto-enhance
enable_highlights boolean true Whether to enable highlights
enable_virtual_text boolean true Whether to enable virtual text (recommended)
virtual_highlight_group string "Comment" Virtual text highlight group
debug boolean false Debug mode (set to true to show all notifications)

Usage

Commands

The plugin provides the following commands:

  • :DockerfileEnhance - Add separator lines to current Dockerfile
  • :DockerfileRemoveSeparators - Remove all separator lines
  • :DockerfileToggleSeparators - Toggle separator line display
  • :DockerfileShowInfo - Show FROM instruction information

Debug Mode

When debug = true, the plugin will show detailed notification information, including:

  • Plugin loading status
  • Dockerfile enhancement results
  • FROM instruction detection information
  • Separator line operation status
-- Enable debug mode
require('dockerfile-enhance').setup({
    debug = true,  -- Show all notifications
    -- Other configurations...
})

-- Temporarily enable debug mode
:lua require('dockerfile-enhance').setup({debug = true})

Examples

Original Dockerfile

FROM node:18-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

FROM base AS development
RUN npm ci
COPY . .
CMD ["npm", "run", "dev"]

FROM base AS production
COPY . .
RUN npm run build
CMD ["npm", "start"]

Enhanced Dockerfile

FROM node:18-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

────────────────────────────────────────────────────────────────────────────────

FROM base AS development
RUN npm ci
COPY . .
CMD ["npm", "run", "dev"]

────────────────────────────────────────────────────────────────────────────────

FROM base AS production
COPY . .
RUN npm run build
CMD ["npm", "start"]

Auto Features

  • When opening a Dockerfile file, the plugin automatically detects and adds separator lines
  • Reapplies highlights when saving files
  • Supported file types: Dockerfile* and *.dockerfile
  • Automatically adds empty lines between FROM instructions (if they don't exist)
  • Uses virtual text mode, doesn't modify file content

Custom Highlighting

You can customize the separator line highlighting styles:

-- Define custom highlight group in colorscheme
vim.api.nvim_set_hl(0, "DockerfileSeparator", {
    fg = "#ff6b6b",
    bold = true
})

-- Use in plugin configuration
require('dockerfile-enhance').setup({
    highlight_group = "DockerfileSeparator",
    virtual_highlight_group = "DockerfileSeparator"  -- Virtual text highlight
})

Usage Scenarios

Daily Use (Recommended Configuration)

require('dockerfile-enhance').setup({
    debug = false,              -- Reduce notification interference
    enable_virtual_text = true, -- Use virtual text mode
    auto_enhance = true,        -- Auto-enhance
})

Development Debugging

require('dockerfile-enhance').setup({
    debug = true,               -- Show detailed notifications
    enable_virtual_text = true, -- Use virtual text mode
    auto_enhance = true,        -- Auto-enhance
})

Contributing

Issues and Pull Requests are welcome!

License

MIT License

About

A Neovim plugin that detects multiple FROM instructions in Dockerfiles and automatically adds separator lines to improve readability of multi-stage builds.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published