2010-10-24 60 views
3

我用褶皺徵求意見一樣我想自定義文本VIM顯示在倒塌的褶皺

# 
Stuff between the # are comments and automatically folded 
# 

但摺疊時,他們看起來像這樣

+-- 4 lines: #-------------------------------------------------------------- 

我寧願他們說

+-- 4 Stuff between the # are comments and automatically folded 

而不是突出顯示,或者是什麼使我們的黑色終端上的白色背景。

我認爲它是foldtext變量,正則表達式超出了我的意思。

回答

1

是的,這是foldtext選項,但你並不需要在這裏正則表達式:把這個變成~/.vim/ftplugin/{filetype}.vim(其中{filetype}應該與這樣的褶皺爲其定義爲某一類文件被替換):

setlocal foldtext='+-'.v:folddashes.'\ '.getline(v:foldstart+1) 
2

另外到方法ZyX顯示你可以分配一個單獨的函數來構建文本,如果你想做更復雜的處理,這是特別有用的。例如,

setlocal foldtext=MyFoldText() 

function! MyFoldText() 
    " do whatever processing you want here 
    " the function will be called for each folded line visible on screen 
    " the line number of each fold's "head" line will be in v:foldstart 
    " last line of fold in v:foldend 
    " can do whatever processing you want, then return text you want 
    " displayed: 

    return my_processed_fold_text 

endfunction 

至於突出,摺疊文本的整個線將具有相同的亮點,這是由「摺疊」高亮組確定。所以,如果你想他們是白色文字,黑色背景:

:hi Folded guifg=white guibg=black ctermfg=white ctermbg=black 

,或者如果你希望他們在灰白色斜體字:

:hi Folded guifg=#bbbbbb guibg=black gui=italic ctermfg=white ctermbg=black 
+0

您的描述符合'foldtext',而不是'foldexpr'(前者用於生成摺疊關閉時顯示的文本,後者僅與'foldmethod = expr'一起使用,並用於自動確定摺疊級別)。 – 2010-10-24 21:27:57

+0

@克里斯 - 謝謝,是的,只是一個錯誤,我修正了。抱歉混淆事物。 foldtext設置可以和foldexpr相同的方式使用單獨的功能,而且有時我會將電線穿過。 – 2010-10-24 23:01:07

0
:hi Folded guifg=green guibg=black ctermfg=green ctermbg=black 

使得它很好的和綠灰色,我可以用它傻子使它看起來不錯

:setlocal foldtext='Comment'.v:folddashes.'\ '.getline(v:foldstart+1).getline(v:foldstart 
+2) 

將填補折的文字,即使我跳過#後面的線,我大概會。

謝謝!現在它更耐人尋味,更有用。

+0

歡迎來到StackOverflow!答案不是評論的方式。您可以使用您學習/接受的信息編輯您的問題。此外,習慣上接受(綠色勾號)答案,你雖然是最有幫助的(而不是隻輸入'謝謝')。 – sehe 2011-04-10 23:19:01

+0

Urff - 安全無視。這是一個古老的問題。我會繼續保持真相和價值 – sehe 2011-04-10 23:20:35