tags:

views:

62

answers:

3

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 # 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.

+1  A: 

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)
ZyX
+1  A: 

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
Herbert Sitz
Your description matches `foldtext`, not `foldexpr` (the former is used to generate the text displayed when a fold is closed, the latter is only used with `foldmethod=expr` and it is used to automatically determine fold level).
Chris Johnsen
@Chris-- Thanks, yes, was just a typo, which I've fixed. Sorry to confuse things. The foldtext setting can use separate function in same way as foldexpr can and I sometimes get my wires crossed.
Herbert Sitz
A: 
: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.

todd