In addition to the ZyX method, you can assign a separate function to create text, which is especially useful if you want to perform more complex processing. For instance.
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 "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 for the selection, the entire line of the folded text will have the same highlight, which is determined by the "Folded" selection group. Therefore, if you want them to be white text on a black background:
:hi Folded guifg=white guibg=black ctermfg=white ctermbg=black
, :
:hi Folded guifg=