【问题标题】:Vim: Custom Folding function done, custom highlighting requiredVim:自定义折叠功能完成,需要自定义突出显示
【发布时间】:2010-03-11 14:08:40
【问题描述】:

我在 vim 中定义了一个函数来正确缩进折叠。即它们看起来像这样:

展开

this is text 
also text
    indented text
    indented text
not indented text

使用默认功能折叠

this is text 
also text
+-- 2 lines: indented text ----------------------------
not indented text

折叠我的新功能

this is text 
also text
    ++- 2 lines: indented text ----------------------------
not indented text

唯一的问题是高亮仍然是这样的:

用我的新功能折叠(用标签突出显示)

this is text 
also text
<hi>    ++- 2 lines: indented text ----------------------------</hi>
not indented text

我希望突出显示从 ++ 开始,而不是从行首开始。我查看了 vim 手册,但找不到类似的东西。我发现的一个一般的解决方案是使背景变黑(与我的背景相同)。

highlight Folded ctermbg=black ctermfg=white cterm=bold

但这会使褶皱不那么明显。

我尝试了以下几种变体:

syn keyword Folded lines
syn region Folded ...

但我认为折叠的选择方式不同,我想不出一种方法来覆盖默认突出显示。谁能给个建议?

顺便说一下,这是我缩进折叠的功能:

set foldmethod=indent

function! MyFoldText()
        let lines = 1 + v:foldend - v:foldstart
        let ind = indent(v:foldstart)

        let spaces = ''
        let i = 0
        while i < ind
                let i = i+1
                let spaces = spaces . ' '
        endwhile

        let linestxt = 'lines'
        if lines == 1
                linestxt = 'line'
        endif

        return spaces . '+' . v:folddashes . ' '. lines . ' ' . linestxt . ': ' . getline(v:foldstaendfunction
endfunction


au BufWinEnter,BufRead,BufNewFile * set foldtext=MyFoldText()

顺便感谢 njd 帮助我设置此功能。

注意:我已经交叉发布了这个 on super user

【问题讨论】:

    标签: unix vim function syntax-highlighting


    【解决方案1】:

    this问题
    似乎我们无法控制折叠突出显示,因为它不是文件的一部分,而是在折叠处临时形成和放置的​​。

    【讨论】:

    • +1:感谢您的链接。这就是我的怀疑。我将把这个问题留几天(希望有人有窍门)。但否则我会接受你的回答。
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多