有沒有辦法使用摺疊或其他Vim腳本黑魔法來隱藏文件頂部的許可證塊?我不喜歡他們佔用我編輯窗格中的很大一部分;我喜歡瞭解一個文件在我第一次打開時的作用,而不是滿臉的樣板。我可以讓Vim忽略文件頂部的許可證塊嗎?
回答
在自動命令試試這個。
function! FoldCopyright
if !exists("b:foldedCopyright")
let b:foldedCopyright = 1
1,15fold
endif
endfunction
適當調整第4行的範圍。在最差的情況下,版權開始於不同的地方,並且這種模式應該是可變長度:
1,/Beginning of copyright/;/End of copyright/
我在fold命令前面使用'silent!'建議,這樣如果許可證塊不存在,Vim就不會抱怨。 – ereOn 2010-05-17 17:03:50
刪除它們怎麼樣?認真。
源代碼受版權所有權和許可保護,而不是樣板文件。它不需要在那裏 - 至少在大多數情況下。
在GPL和其他類似方案的情況下,它們有效地要求文本存在,它可以移動到文件的底部或任何其他地方。
如果希望人們首先閱讀**相關許可證信息** Vim足夠強大,可以自動輕鬆地摺疊它,所以它沒什麼大不了的...... – ereOn 2010-05-17 09:06:39
這取決於是否存在與許可證塊一致的形式以及您正在編程的語言。例如,python傾向於使用'foldexpr'來定義摺疊,因此要添加它,您必須替換現有的功能與新的功能(或擺脫現有的摺疊)。我相信C中的默認值是使用手動摺疊(儘管可能我自己配置了這種方式:我不記得了),因此添加額外摺疊更容易。
通過一個簡單的GPL版權信息,就像本文末尾的GPL版權信息一樣,您可以將foldmethod設置爲manual,並有一個簡單的函數來創建摺疊。這完全取決於版權的形式,以及保持現有摺疊的重要性。恐怕我需要更多的細節來給出更有用的答案。不管怎樣,下面是可以用來版權聲明在這篇文章的末尾折一個示例腳本:
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...
- 1. 我可以讓pytest doctest模塊忽略一個文件嗎?
- 2. 我可以讓vim尊重我的.gitignore文件嗎?
- 3. 我可以讓Postgresql忽略交易中的錯誤嗎?
- 4. 可以忽略DbUpdateConcurrencyException嗎?
- 5. 我可以忽略文本框上的輕按事件嗎?
- 6. 我可以忽略Windows SVN中的單個文件嗎?
- 7. 我可以讓Java 5忽略@Override錯誤嗎?
- 8. 我可以讓Textmate完成忽略大寫嗎?
- 9. 我可以讓rubygems忽略寶石版本衝突嗎?
- 10. 我可以讓schemacrawler忽略模式名稱嗎?
- 11. 我可以指示jar命令忽略.svn文件夾嗎?
- 12. iPhone:我可以讓一個UIDatePicker出現在UIKeyboard的頂部嗎?
- 13. 如何讓Visual Studio在每個文件的頂部添加開源許可證
- 14. 當計算忽略時,git可以忽略嵌套的.gitignore文件嗎?
- 15. 我可以忽略rails靜態文件夾中的asp文件嗎?
- 16. Grails中的HeuristicCompletionException可以忽略嗎?
- 17. 我如何忽略SourceTree中的不可忽略文件(Git)
- 18. 忽略SVN忽略...可能嗎?
- 19. oozie可以忽略缺少的輸入文件嗎?
- 20. can bazaar可以忽略分支中已存在的文件嗎?
- 21. Can SimpleTemplate可以忽略模板文件中的變量嗎?
- 22. 可以rpmbuild忽略buildroot中的文件嗎?
- 23. 我可以忽略「無法同時滿足約束條件」嗎?
- 24. UIView可以「忽略」界面方向嗎?
- 25. Haskell可以忽略Ints與整數嗎?
- 26. SUMPRODUCT可以忽略空白單元嗎?
- 27. Stanford Parser可以忽略大小寫嗎?
- 28. 可以忽略返回值嗎?
- 29. 我可以告訴findbugs忽略我無法添加的類嗎?
- 30. Qt可以限制我的免費許可證的商業部署嗎?
想要忽略的文本格式是什麼? – 2010-02-12 16:50:08