I want to customize the text vim shows in collapsed folds
I use folds for comments like
#
Stuff between the # are comments and automatically folded
#
But when folded they look like this
+-- 4 lines: #--------------------------------------------------------------
I would rather have them say
+-- 4 Stuff between the开发者_StackOverflow中文版 # are comments and automatically folded
and not be highlighted, or whatever makes them white background on my black terminal.
I think its the foldtext variable, and the regex-ing is beyond me.
In addition to method ZyX shows you can assign a separate function to build the text, which is especially useful if you want to do more complicated processing. E.g.,
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
As far as highlighting, the entire line of folded text will have same highlight, which is determined by the 'Folded' highlight group. So if you want them to be white text on a black background:
:hi Folded guifg=white guibg=black ctermfg=white ctermbg=black
or if you want them in off-white italics:
:hi Folded guifg=#bbbbbb guibg=black gui=italic ctermfg=white ctermbg=black
Yes, it is the foldtext
option, but you do not need regex here: put this into ~/.vim/ftplugin/{filetype}.vim
(where {filetype}
should be replaced with a filetype for which such folds are defined):
setlocal foldtext='+-'.v:folddashes.'\ '.getline(v:foldstart+1)
:hi Folded guifg=green guibg=black ctermfg=green ctermbg=black
made it nice and green on grey, and I can fool with it to make it look nice
:setlocal foldtext='Comment'.v:folddashes.'\ '.getline(v:foldstart+1).getline(v:foldstart
+2)
Will fill up the fold text, even if I skip a line after the #, which I probably will.
THANKS! It is much more bearable and useful, now.
精彩评论