Generate copyright headers for any open source license
Contents
Mostly written in CPython, this (neo)vim plugin fetches the license of your choice directly from the SPDX License List. If the XML response contains a standard header, it's inserted at the top of the current buffer with your copyright info.
When no standard header is provided, you can either insert a brief license
acknowledgment, or the full license text. (See the g:cpywrite#verbatim_mode
option below.)
This plugin learns your name and email by invoking git. If that fails, the
copyright line will contain your OS user and host names.
- Python bindings compatible with python 3.7+, depending on your platform and (neo)vim version, of course
| NOTE: | Python 3.10 requires neovim 0.6.0 or newer. All vim versions from 8.1 and up should be compatible. Bug reports are welcome. | 
|---|
- Choose from more than 420 licenses (press <tab>after the:CPYwriteDefaultLicenseor:CPYwritecommand for suggestions)
- No dependency on other plugins. That said, neovim users will be grateful to
have the completeopt feature when tabbing through all the available
licenses. Vim users may want to add set wildmenuto their.vimrcfile
| :CPYwrite [{spdx_short_name}] | Fetches the license identified by spdx_short_name(without quotes) --
uses the current value ofg:cpywrite#default_licensewhen no
argument is given -- supports<tab>completion | 
| :CPYwriteDefaultLicense [{spdx_short_name}] | Sets g:cpywrite#default_licenseto the
license identified byspdx_short_name(without quotes) -- prints the default
licence id when called with no argument --
supports<tab>completion | 
| :CPYwriteKeepShebangs | Switches g:cpywrite#preserve_shebangson or off | 
| :CPYwriteToggleMode | Switches g:cpywrite#verbatim_modeon or
off | 
| :CPYwriteToggleStyle | Switches g:cpywrite#machine_readableon
or off | 
| :CPYwriteToggleFilename | Switches g:cpywrite#hide_filenameon or
off | 
| :CPYwriteAllowAnonymous | Switches g:cpywrite#no_anonymouson or
off | 
| <Plug>(cpywrite) | Does the same as calling :CPYwritewith
no argument | 
| {Normal}LH | Maps to <Plug>(cpywrite) | 
| g:cpywrite#default_license | The SPDX identifier of the license to be
fetched by the :CPYwritecommand.
Default:'Apache-2.0' | 
| g:cpywrite#preserve_shebangs | When set to a non-zero value, the license
header is inserted after any shebang or
encoding directive (since 0.7.0).
Default: 1 | 
| g:cpywrite#verbatim_mode | When set to a non-zero value, the full
license text will be requested -- you should
only choose this when the license is no
longer than 3-4 paragraphs (e.g. Unlicense,
MIT, BSD 1- 2- 3-Clause, etc.).
Default: 0 | 
| g:cpywrite#no_anonymous | When set to a non-zero value, copyright
information is never omitted, even if the
license implies a Public Domain grant.
Default: 0 | 
| Has no effect when g:cpywrite#machine_readableis on | |
| g:cpywrite#machine_readable | When set to a non-zero value, the license
and copyright statement are formatted as
tags.
Default: 0 | 
| Overrides g:cpywrite#verbatim_modeandg:cpywrite#no_anonymous | |
| g:cpywrite#hide_filename | When set to a non-zero value, hides the name
of the current buffer from the license header
in all modes.
Default: 0 | 
| g:cpywrite#java#add_class_doc | When set to a non-zero value, :CPYwritewill try to insert an appropriate@authortag into an existing JavaDoc comment above
the main class definition.
Default:1(file type must bejava) | 
- Vim compiled with any one of the +python3 or +python3/dyn options.
See if you're supported by entering vim --version | grep +python3at your terminal, or startvimand enter the:versioncommand
- Neovim with the pynvim module in your $PYTHONPATH. Startnvimand enter:help provider-pythonfor more information
If pynvim is not already in your $PYTHONPATH, install it:
pip install --user -U pynvim
If you have vim 8+, you can directly copy the plugin source tree to your native package directory:
git clone https://github.com/rdipardo/vim-cpywrite ~/.vim/pack/*/start/vim-cpywrite
Note. You can replace * with any name you want (e.g. plugins)
Learn more by typing :help packages into your vim command prompt.
You should also read about DIY plugin management.
Users of older vim versions can simulate native package loading with vim-pathogen.
Using lazy.nvim
In ~/.config/nvim/lua/config/lazy.lua, or, optionally,
in ~/.config/nvim/init.lua:
require("lazy").setup({
   -- ...
   {
      "rdipardo/vim-cpywrite",
      config = function()
         -- https://github.com/rdipardo/vim-cpywrite#options
         -- for example:
         vim.g["cpywrite#default_license"] = "MIT"
      end
   },
   -- ...
})Using plug.vim
Edit your ~/.vimrc, ~/.vim/vimrc, or ~/.config/nvim/init.vim:
call plug#begin('~/path/to/your/plugin/directory/')
Plug 'rdipardo/vim-cpywrite'
call plug#end()Using Vundle
Install Vundle:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
or (if using neovim):
git clone https://github.com/VundleVim/Vundle.vim.git ~/.config/nvim/bundle/Vundle.vim
Edit your ~/.vimrc, ~/.vim/vimrc, or ~/.config/nvim/init.vim:
set rtp+=~/.vim/bundle/Vundle.vim
"or:
"set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin()
Plugin 'rdipardo/vim-cpywrite'
call vundle#end()- header.nvim
- 42header
- vim-copyright (not a fork)
- vim-licenses, formerly licenses
- vim-header
- license-to-vim
- license loader
☐ Provide a batch mode for licensing all tracked files in a working tree
☐ Provide the option to set user-defined authorship details
☑ Expand the list of supported programming languages
Consider opening a PR with an updated installation guide if any of the following applies to you:
- installation fails
- installation succeeds with a plugin manager not mentioned here
Distributed under the terms of the MIT license.
