【发布时间】: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