I want to configure text vim shows in folded folds

I use folds for comments, for example

#
Stuff between the # are comments and automatically folded
#  

But when they are folded, they look like this:

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

I would rather they say

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

and not stand out, or something else makes them a white background on my black terminal.

I think this is a foldtext variable, and regex-ing is outside of me.

+3
source share
3 answers

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=#bbbbbb guibg=black gui=italic ctermfg=white ctermbg=black
+2

, foldtext, : ~/.vim/ftplugin/{filetype}.vim ( {filetype} , ):

setlocal foldtext='+-'.v:folddashes.'\ '.getline(v:foldstart+1)
+1
:hi Folded guifg=green guibg=black ctermfg=green ctermbg=black

made him beautiful and green on gray, and I can fool him to look beautiful

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

Will fill up the addition text even if I skip the line after #, which is likely to be.

THANK! Now it is much more tolerant and useful.

0
source

Source: https://habr.com/ru/post/1771200/


All Articles