header.nvim is a Neovim plugin which adds or updates brief author information and license headers to the top of the files.
header.nvim.mp4
- Add new copyright header
- Update existing copyright header
- Add common licenses
- Neovim 0.8+
with packer.nvim
use({ "attilarepka/header.nvim", config = function() require("header").setup() end})with lazy.nvim
{"attilarepka/header.nvim", config = true}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,
}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",
})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):AddHeaderAdds brief copyright information
:AddLicenseAGPL3Adds AGPL3 License:AddLicenseAPACHEAdds Apache License:AddLicenseBSD2Adds BSD2 License:AddLicenseBSD3Adds BSD3 License:AddLicenseCC0Adds CC0 License:AddLicenseGPL3Adds GPL3 License:AddLicenseISCAdds ISC License:AddLicenseMITAdds MIT License:AddLicenseMPLAdds MPL License:AddLicenseUNLICENSEAdds Unlicense License:AddLicenseWTFPLAdds WTFPL License:AddLicenseX11Adds X11 License:AddLicenseZLIBAdds ZLIB License
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",
})Contributions are welcome! Open a GitHub issue or pull request.
This project is licensed under the MIT license