2015-02-24 39 views
1

我正在使用手動摺疊來編寫perl程序。下面是一個典型摺疊:爲什麼第一個散列標記在vim中消失?

sub do_something # does something --{{{ 
{ 
    # perl code here 
} # --}}} 

當摺疊時,這四行被如此顯示:

+-- 4 lines: sub do_something does something ---------------------------- 

在摺疊版本,字之前的散列標記「並」已經消失了。爲什麼?如果這是一項功能,我該如何禁用它?作爲一種解決方法,我寫'sub do_something ##做了一些事情 - {{{',但有沒有一種乾淨的方式讓vim顯示我輸入的內容? (也許這與perl.vim有什麼關係?)

回答

3

什麼顯示而不是摺疊線由'foldtext'選項控制。默認情況下,使用內部功能foldtext():help foldtext()解釋說:

The returned string looks like this: 
     +-- 45 lines: abcdef 
    The number of dashes depends on the foldlevel. The "45" is 
    the number of lines in the fold. "abcdef" is the text in the 
    first non-blank line of the fold. Leading white space, "//" 
    or "/*" and the text from the 'foldmarker' and 'commentstring' 
    options is removed. 

正如你看到的,這是Vim中的啓發式算法來減少混亂。要關閉:

  1. 您可以清除'commentstring';它僅用於添加手動摺疊標記(並且一些評論插件可以依靠它作爲後備),將:setlocal commentstring=放入~/.vim/after/ftplugin/perl.vim
  2. 您可以編寫自己的摺疊功能(示例和說明,網址爲:help fold-foldtext),然後全局安裝,或者(如上述替代方法)僅針對Perl文件類型進行安裝。