例如,如果我在vim中打开一个全新的文件,它已经包含以下文本:
/* The MIT License Copyright (c) 2009 Apphacker apphacker@gmail.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
为每个新文件输入/复制并粘贴它会很烦人.
如何创建保存MIT许可证的文本文件〜/ .vim/mit.txt?然后是.vimrc中的以下内容:
map :mit :0r ~/.vim/mit.txt
...所以你只需输入:用于插入许可证的mit.
或者,如果您确实一直想要这种行为:
autocmd BufNewFile * \ 0r ~/.vim/mit.txt augroup END
正如http://www.gnu.org/copyleft/gpl.html所说,
为此,请将以下注意事项附加到程序中.最安全的做法是将它们附加到每个源文件的开头,以最有效地说明不包括保修; 并且每个文件至少应具有"copyright"行和指向完整通知所在位置的指针.
因此,能够自动插入一些文本可能很有用.该snipMate插件可用于这一目的.虽然它是专为代码片段设计的,但它也可用于自动插入一些任意文本.
安装snipMate后,将以下代码块附加到〜.vim\snippets_.snippets文件中的文件中.
snippet mit /* The MIT License Copyright (c) `strftime("%Y")` ${1:Your name here} ${2:Your email here} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
现在,当你输入
mit
并按
它会插入上面的文字.它还将调整日期,它会自动将光标移动到名称和电子邮件部分.
因此,您可以将许可证(GNU,MIT,您将其命名)添加到该文件中,并在需要时随时使用.