我能得到的Vim忽略文件的顶部许可证块?
-
20-09-2019 - |
题
有没有使用折叠或其它Vim脚本的黑魔法在文件的顶部,以隐藏许可证区块的方法吗?我不喜欢,他们采取了我的编辑窗格的这样一大段;我想获得什么文件是做当我第一次打开它,而不是一个意义上的脸满样板。
解决方案
尝试这在自动命令。
function! FoldCopyright
if !exists( "b:foldedCopyright" )
let b:foldedCopyright = 1
1,15fold
endif
endfunction
调整在第4行的范围内适当地。另外,在版权开始于不同的地方,是可变长度这个图案应该做最坏的情况下:
1,/Beginning of copyright/;/End of copyright/
其他提示
这取决于是否有一个一致的形式将许可证块,什么语言你在编程。例如,蟒蛇倾向于使用“foldexpr”里定义折叠,所以要加这个,你就必须更换现有功能与一个新的(或摆脱现有的折叠)。我相信,在C,其默认是使用手动折叠(尽管它可能是我设置这种方式自己:我记不清了),所以这是很容易添加额外的折叠
。使用像一个在该柱的端部的简单GPL版权信息,可以使用foldmethod设置为手动,并有一个创建折叠的简单函数。这一切都依赖于版权的形式,是多么重要是让你保持现有的折叠上。我怕我会需要更多的细节,以提供更有效的答案。不管怎样,下面是可以用来版权声明在这个帖子的末尾折一个示例脚本:
function! CreateCopyrightFold()
let InCopyright = 0
set foldmethod=manual
for Line in range(1,line('$'))
let LineContents = getline(Line)
if LineContents !~ "^#"
if InCopyright
let CopyrightEnd = Line - 1
exe CopyrightStart . ',' . CopyrightEnd . 'fold'
endif
break
elseif LineContents =~ "Copyright"
let InCopyright = 1
let CopyrightStart = Line
endif
endfor
endfunction
au BufRead *.py call CreateCopyrightFold()
假设像这样的版权通知:
# Copyright (C) 2009 Some Company or Something
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import sys
# Code continues...
我创建了一个小的vim插件此。它占卜时,页面的第一条评论,应折。它的工作在我的测试案例,但是,当然,任何改善是值得欢迎的。它应该是易加入等单个或多个线路标识符
获取它这里 。要安装,就像任何其他的插件,只需拖放到你的〜/ vim的/插件。
编辑:更改为vim.org链路和清理答案
怎么样删除呢?严重。
源代码是由权利所有权和许可,而不是样板保护。它并不需要在大多数情况下,至少
在GPL和其它类似的方案,其不要求有效的文本存在的情况下,它可以被移动到文件的底部或任何
不隶属于 StackOverflow