sponsor Vim development Vim logo Vim Book Ad

vim-cpywrite : Generate copyright headers for any open source license

 script karma  Rating 8/2, Downloaded by 1466  Comments, bugs, improvements  Vim wiki

created by
Robert Di Pardo
 
script type
utility
 
description
Pass a license identifier to the :CPYwrite command and it will insert the
standard header, if available, at the top of the current buffer.

When g:cpywrite#verbatim_mode is off, licenses with no standard header will
be acknowledged below your author line. Turn on g:cpywrite#verbatim_mode to
use the full license text instead.

When g:cpywrite#machine_readable is on, license and copyright are formatted
for easier parsing by a validation tool like reuse (https://reuse.readthedocs.io).

This plugin learns your name and email by invoking `git`; it falls back to
your OS user and host names.


Quick Reference
----------------------
: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


:CPYwriteKeepShebangs

Toggles the state of the g:cpywrite#preserve_shebangs option and prints a
description of the current state:

    0 == "overwrite"
    1 == "preserve existing"


:CPYwriteDefaultLicense [{spdx_short_name}]

Sets g:cpywrite#default_license to the given SPDX license identifier (without
quotes) and prints the updated value. Use <tab> for name completion.

Simply prints g:cpywrite#default_license when called with no argument.


:CPYwriteToggleMode

Toggles the state of the g:cpywrite#verbatim_mode option and prints a
description of the current state:

    0 == "standard header/brief"
    1 == "verbatim"


:CPYwriteToggleStyle

Toggles the state of the g:cpywrite#machine_readable option and prints a
description of the current state:

    0 == "descriptive"
    1 == "machine readable"


:CPYwriteToggleFilename

Toggles the state of the g:cpywrite#hide_filename option and prints a
description of the current state:

    0 == "showing"
    1 == "hidden"


:CPYwriteAllowAnonymous

Toggles the state of the g:cpywrite#no_anonymous option and prints a
description of the current state:

    0 == "Public Domain only"
    1 == "never" // meaning, "always state the copyright holder"


<Plug>(cpywrite)

Does the same as calling :CPYwrite with no argument


{Normal}LH

Maps to <Plug>(cpywrite)


Options
----------
g:cpywrite#default_license (string; default: 'Apache-2.0')

Set this to the SPDX identifier of your favourite license. Press <tab> after
the :CPYwriteDefaultLicense or :CPYwrite command for suggestions.


g:cpywrite#preserve_shebangs (number; default: 1)

When set to a non-zero value, the license header is inserted after any shebang
line: `#! . . .`, or encoding directive: `# -*- coding: . . . -*-`

When set to 0, shebangs and encoding directives will be overwritten. A template
shebang line is inserted at the top of perl, python, and shell script files.


g:cpywrite#verbatim_mode (number; default: 0)

When set to a non-zero value, the full license text will be requested, whether
or not a standard header exists. 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.)

When set to 0, only standard headers are requested. Licenses with no standard
header will be briefly mentioned below your copyright line.


g:cpywrite#no_anonymous (number; default: 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WARNING
this option has no effect when g:cpywrite#machine_readable is on
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When set to a non-zero value, copyright information is never omitted, even if
the license implies a Public Domain grant.

When set to 0, a copyright will not appear above Public-Domain-licenses.


g:cpywrite#machine_readable (number; default: 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WARNING
this option overrides g:cpywrite#verbatim_mode and g:cpywrite#no_anonymous
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When set to a non-zero value, the license and copyright statement are
formatted as tags, for example:

  #
  # __main__.py
  #
  # SPDX-FileCopyrightText: 2020 Jane Doe <jane@example.com>
  #
  # SPDX-License-Identifier: GPL-3.0-or-later
  #

In this mode, copyright information is never omitted, regardless of how
g:cpywrite#no_anonymous has been set, e.g.

  /**
   * main.js
   *
   * SPDX-FileCopyrightText: 2020 John Doe <john@example.com>
   *
   * SPDX-License-Identifier: Unlicense
   */

When set to 0, the license format will be a standard header, or full text,
depending on how g:cpywrite#verbatim_mode is set. A copyright statement
may also be left out if g:cpywrite#no_anonymous is 0 and the chosen
license is a Public Domain license.


g:cpywrite#hide_filename (number; default: 0)

When set to a non-zero value, hides the name of the current buffer from the
license header in all modes. Otherwise, the buffer's name will appear on the
first line.


g:cpywrite#java#add_class_doc (number; default: 1)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTE
if not set by the user, this option will be enabled automatically when 'filetype' is 'java'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When set to a non-zero value, adds a JavaDoc '@author' tag to the main class
definition of the current Java file, if:

    1. the class already has a doc comment of >= 3 lines; and
    2. at least one line is blank, e.g.

    /**
     *
     */
    public class Main {}


Testing Locally
--------------------
  * install vader.vim (vimscript #4832) into your runtime path

  * alternatively, run `git clone https://github.com/junegunn/vader.vim.git` and
    edit `test/vimrc` by changing

     set rtp+=vader.vim

    to

     set rtp+=/path/to/cloned/source/of/vader.vim

  * change directories into /your/plugin/path/vim-cpywrite

  * issue these commands:

     pip install -r test/requirements.txt
     coverage run -m pytest -v && coverage report
     vim -ENsu test/vimrc -c '+Vader! test/vader/**' > /dev/null

 
install details
Make sure your environment has the requirements listed at https://github.com/rdipardo/vim-cpywrite#requirements

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTE
python 3.10 requires neovim 0.6.0 or newer;
all vim versions from 7.4 and up should be compatible
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For a detailed installation guide, refer to https://github.com/rdipardo/vim-cpywrite#installation
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-cpywrite-0.8.2.tar.gz 0.8.2 2024-09-01 7.4 Robert Di Pardo New file type: Cpp2/cppfront; more extension mappings for Pascal; improved error message for Neovim
vim-cpywrite-0.8.1.tar.gz 0.8.1 2023-07-31 7.4 Robert Di Pardo Bugfix for generated author bylines; new licenses; python 2.7 is no longer supported
vim-cpywrite-0.7.0.tar.gz 0.7 2022-01-11 7.4 Robert Di Pardo Fix missing copyright in GPL v1 and 2 headers; use the `&syntax` property to improve detection of dotfiles, makefiles, and scripts; add support for reStructuredText, YAML, and more
vim-cpywrite-0.6.0.tar.gz 0.6 2021-10-02 7.4 Robert Di Pardo New option to format license and copyright as machine readable tags (REUSE compatible), support for DOS Batch files
vim-cpywrite-0.5.0.tar.gz 0.5.0 2021-07-03 7.4 Robert Di Pardo Support three new file types, insert header after [X|HT]ML metadata
vim-cpywrite-0.4.0.tar.gz 0.4.0 2021-05-25 7.4 Robert Di Pardo - include recent additions to the SPDX License List
- drop the deprecated FreeBSD variant of the BSD 2-Clause License
- change default license
vim-cpywrite-0.3.4.tar.gz 0.3.4 2021-04-04 7.4 Robert Di Pardo Handle missing emails, fix regex bugs, reduce plugin size
vim-cpywrite-0.3.0.tar.gz 0.3.0 2020-10-12 7.4 Robert Di Pardo Provide option to hide buffer name in license header, support for more file types
vim-cpywrite-0.2.1.tar.gz 0.2.1 2020-08-17 7.4 Robert Di Pardo Support more file types, detect public domain licenses
vim-cpywrite.tar.gz 0.1.0 2020-06-13 7.4 Robert Di Pardo Initial upload
ip used for rating: 18.97.9.175

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github