0

Extend of this question of fold: Fold: foldtext() for each filetype

We have fold for each filetype now but each fold need different highlight style of color, because highlight is global I tried to set it in after/ftplugin/rust/folding.vim and then reset it back to my favor default one but it doesn't effect.

Inconsistent behavior like if vim enter buffer of rust it set to new hi and then if leave rust buffer file it still persist the rust's hi for other buffers, that is not expected, leave rust buffer should set hi back to default and other buffers should take the default one instead of the new rust hi.

Like below:

if exists('b:undo_ftplugin')
  let b:undo_ftplugin .= ' | '
else
  let b:undo_ftplugin = ''
endif

" set highlight here for this specific fold
hi Fold ctermfg=10 ctermbg=12

" This is where my local foldtext() function for rust.vim
foldtext() <...>

if !exists("*MyRustFtpluginUndo")
  function MyCFtpluginUndo()
    setlocal tags<
    setlocal path<
    silent! nunmap <buffer> <LocalLeader>tr

    " set highlight back to default one
    hi Fold ctermfg=5 ctermbg=6
  endfunction
endif

let b:undo_ftplugin .= 'call MyRustFtpluginUndo()'

Note about: hi Fold ctermfg=10 ctermbg=12 and hi Fold ctermfg=5 ctermbg=6

0

Solution: we just need to set this hi Fold ctermfg=10 ctermbg=12 in each fold file of each filetype, because of this set global, make sure to set to your favor hi of Folded, if not set, Folded of previous folding will take place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.