更改折叠中的文本 [英] Change the text in folds
问题描述
我注意到折叠文本可以显示有用的信息.他们通常会显示类似
+-- 5 行:<div id="header-inner">-------------------------------------------
是否可以更改这些行中的文本?我注意到在 foldexpr
中有些东西是可能的,但是否有可能完全重新设计折叠?
例如+
谢谢
从你的问题中我有一些不明白的地方,比如你使用的是哪种折叠方法,或者行"的数量是指什么,但这里有一个自定义的 foldtext 函数,它应该可以大致满足您的要求:
函数!我的折叠文本()让 nl = v:foldend - v:foldstart + 1让评论 = 替代(getline(v:foldstart),^ *",",1)让 linetext = 替代(getline(v:foldstart+1),"^ *","",1)让 txt = '+ ' .行文本.':'.评论.'":长度'.nl返回txt端功能设置 foldtext=MyFoldText()
说明:
- 找出折叠包含的行数.
- 从第一条折叠线之前的行中获取注释"(并删除前导空格).
- 从折叠的第一行获取文本(并删除前导空格).
- 使用适当的格式将上述信息组合到返回的折叠文本中.
希望这会有所帮助.它应该可以轻松满足您的需求.
I noticed that fold texts can show useful information. They usually show something like
+-- 5 lines: <div id="header-inner">--------------------------------------------
Is it possible to change the text in those lines? I noticed that something is possible in foldexpr
but would it be possible to completely redesign folds?
e.g.
+ <div id="header-inner"> : "possible comment from line above" : row 27 : length 5
thank you
There are a few things I don't understand from your question, such as which foldmethod you are using, or what the number of "rows" refers to, but here's a custom foldtext function that should do roughly what you want:
function! MyFoldText()
let nl = v:foldend - v:foldstart + 1
let comment = substitute(getline(v:foldstart),"^ *","",1)
let linetext = substitute(getline(v:foldstart+1),"^ *","",1)
let txt = '+ ' . linetext . ' : "' . comment . '" : length ' . nl
return txt
endfunction
set foldtext=MyFoldText()
Explanation:
- Find the number of lines contained by the fold.
- Get the "comment" from the line before the first folded line (and remove leading spaces).
- Get the text from the first line of the fold (and remove leading spaces).
- Assemble the above information into the returned foldtext, with appropriate formatting.
Hope this helps. It should be easily tailored to your needs.
这篇关于更改折叠中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!