I want to customize the text vim shows in collapsed folds

狂风中的少年 提交于 2020-01-23 11:47:28

问题


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:


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



回答2:


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)



回答3:


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



来源:https://stackoverflow.com/questions/4009979/i-want-to-customize-the-text-vim-shows-in-collapsed-folds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!