8000 GitHub - attilarepka/header.nvim: Add or update copyright and license headers in any source file—right from Neovim
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

attilarepka/header.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

header.nvim

Fast, minimal Neovim plugin to automatically add or update copyright and license headers in any programming language.

header.nvim demo

Features

  • Add new copyright header
  • Update existing copyright header
  • Add common licenses, see here
  • Project specific configuration, see here
  • Keybindings, see here

Prerequisites

  • Neovim 0.8+

Installing

with packer.nvim

use({ "attilarepka/header.nvim", config = function() require("header").setup() end})

with lazy.nvim

{"attilarepka/header.nvim", config = true}

Setup

The script comes with the following defaults:

{
    file_name = true,
    author = nil,
    project = nil,
    date_created = true,
    date_created_fmt = "%Y-%m-%d %H:%M:%S",
    date_modified = true,
    date_modified_fmt = "%Y-%m-%d %H:%M:%S",
    line_separator = "------",
    copyright_text = nil,
}

Override configuration

To override the custom configuration, call:

require("header").setup({
  -- your override config
})

Example:

require("header").setup({
    file_name = true,
    author = "Foo",
    project = "header.nvim",
    date_created = true,
    date_created_fmt = "%Y-%m-%d %H:%M:%S",
    date_modified = true,
    date_modified_fmt = "%Y-%m-%d %H:%M:%S",
    line_separator = "------",
    copyright_text = "Copyright 2023",
})

Project specific configuration

The default configuration can be overwritten by a local project .header.nvim file with the following format:

{
  "file_name": true,
  "author": "Your Name",
  "project": "Your Project",
  "date_created": true,
  "date_created_fmt": "%Y-%m-%d %H:%M:%S",
  "date_modified": true,
  "date_modified_fmt": "%Y-%m-%d %H:%M:%S",
  "line_separator": "------",
  "copyright_text": "Copyright (c) 2023 Your Name"
}

Keybindings

To setup custom keybindings:

local header = require("header")

vim.keymap.set("n", "<leader>hh", function() header.add_headers() end)
-- see supported licenses below, method handles case-insensitively
vim.keymap.set("n", "<leader>hm", function() header.add_license_header("mit") end)

Commands

Adding Headers

  • :AddHeader Adds brief copyright information

Adding Licenses

  • :AddLicenseAGPL3 Adds AGPL3 License
  • :AddLicenseAPACHE Adds Apache License
  • :AddLicenseBSD2 Adds BSD2 License
  • :AddLicenseBSD3 Adds BSD3 License
  • :AddLicenseCC0 Adds CC0 License
  • :AddLicenseGPL3 Adds GPL3 License
  • :AddLicenseISC Adds ISC License
  • :AddLicenseMIT Adds MIT License
  • :AddLicenseMPL Adds MPL License
  • :AddLicenseUNLICENSE Adds Unlicense License
  • :AddLicenseWTFPL Adds WTFPL License
  • :AddLicenseX11 Adds X11 License
  • :AddLicenseZLIB Adds ZLIB License

Autocommand for update date modified when saving a file

local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd

augroup("mygroup", { clear = true })

autocmd("BufWritePre", {
    pattern = "*",
    callback = function()
        local header = require("header")
        if header and header.update_date_modified then
            header.update_date_modified()
        else
            vim.notify_once("header.update_date_modified is not available", vim.log.levels.WARN)
        end
    end,
    group = "mygroup",
    desc = "Update header's date modified",
})

Contributing

Contributions are welcome! Open a GitHub Issue or Pull request.

License

This project is licensed under the MIT license

About

Add or update copyright and license headers in any source file—right from Neovim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0