Skip to content

rdipardo/vim-cpywrite

Repository files navigation

vim-cpywrite

Build Status Coverage stats Vim Scripts version

Generate copyright headers for any open source license

vim-win-x64-demo

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 7.4 and up should be compatible. Bug reports are welcome.
  • Choose from more than 420 licenses (press <tab> after the :CPYwriteDefaultLicense or :CPYwrite command 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 wildmenu to their .vimrc file
:CPYwrite [{spdx_short_name}] Fetches the license identified by spdx_short_name (without quotes) -- uses the current value of g:cpywrite#default_license when no argument is given -- supports <tab> completion
:CPYwriteDefaultLicense [{spdx_short_name}] Sets g:cpywrite#default_license to the license identified by spdx_short_name (without quotes) -- prints the default licence id when called with no argument -- supports <tab> completion
:CPYwriteKeepShebangs Switches g:cpywrite#preserve_shebangs on or off
:CPYwriteToggleMode Switches g:cpywrite#verbatim_mode on or off
:CPYwriteToggleStyle Switches g:cpywrite#machine_readable on or off
:CPYwriteToggleFilename Switches g:cpywrite#hide_filename on or off
:CPYwriteAllowAnonymous Switches g:cpywrite#no_anonymous on or off
<Plug>(cpywrite) Does the same as calling :CPYwrite with no argument
{Normal}LH Maps to <Plug>(cpywrite)
g:cpywrite#default_license The SPDX identifier of the license to be fetched by the :CPYwrite command. 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_readable is 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_mode and g: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, :CPYwrite will try to insert an appropriate @author tag into an existing JavaDoc comment above the main class definition. Default: 1 (file type must be java)
  • Vim compiled with any one of the +python3 or +python3/dyn options. See if you're supported by entering vim --version | grep +python3 at your terminal, or start vim and enter the :version command
  • Neovim with the pynvim module in your $PYTHONPATH. Start nvim and enter :help provider-python for 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 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()

☐ 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.