更改折叠中的文本

发布于 2024-11-06 11:06:38 字数 331 浏览 0 评论 0原文

我注意到折叠文本可以显示有用的信息。它们通常显示类似

+-- 5 行:

------------------------ --------------------

是否可以更改这些行中的文本?我注意到 foldexpr 中有些东西是可能的,但是否可以完全重新设计折叠?
例如
+

; :“上面一行可能有注释”:第 27 行:长度 5

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲娇萝莉攻 2024-11-13 11:06:38

从你的问题中我不明白一些事情,例如你正在使用哪种折叠方法,或者“行”数指的是什么,但这里有一个自定义的折叠文本函数,它应该大致完成你想要的操作:

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()

解释:

  1. 查找折叠所包含的行数。
  2. 从第一条折叠行之前的行获取“注释”(并删除前导空格)。
  3. 从折叠的第一行获取文本(并删除前导空格)。
  4. 使用适当的格式将上述信息组装到返回的折叠文本中。

希望这有帮助。它应该可以轻松地根据您的需求进行定制。

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:

  1. Find the number of lines contained by the fold.
  2. Get the "comment" from the line before the first folded line (and remove leading spaces).
  3. Get the text from the first line of the fold (and remove leading spaces).
  4. Assemble the above information into the returned foldtext, with appropriate formatting.

Hope this helps. It should be easily tailored to your needs.

双手揣兜 2024-11-13 11:06:38

您还可以从 Steve Losh 的 bitbucket 存储库页面关于vim

它的外观非常漂亮,也非常有组织性!

要了解它是什么样的,您可以在这个 youtube 视频中查看。

You can also inspect the folding config from Steve Losh’s bitbucket repo page about vim.

It has very beautiful appearance, which is also very organized!

To see what it is like, you might ckeck it out in this youtube video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文