Vim:完成自定义折叠功能,需要自定义突出显示

时间:2010-03-11 14:08:41

标签: unix vim function syntax-highlighting

我在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

1 个答案:

答案 0 :(得分:2)

请参阅this问题 似乎我们无法控制折叠高亮,因为它不是文件的一部分,而是在折叠处形成和暂时放置。

相关问题