ViM syntax highlighting based on column
I have a column-formatted text file that I'd like highlighted in ViM. I want to highlight the file like this:
I have seen examples of highlighting based on regular expressions or keywords, but I'm not sure how to do this based solely on the column of the file.
Is this even possible?
这实际上很简单,因为vim具有与特定列号匹配的模式语法:
syn region Red start="%61c" end="%66c"
syn region Blue start="%66c" end="%71c"
syn region Green start="%71c" end="%81c"
hi Red ctermfg=Red guifg=Red
hi Blue ctermfg=Blue guifg=Blue
hi Green ctermfg=Green guifg=Green
define your own hi-groups:
:hi Red ctermfg=red guifg=red
:hi Green ctermfg=green guifg=green
:hi Blue ctermfg=blue guifg=blue
execute this:
:match Red /%>60v.*%<66v/
:2match Blue /%>65v.*%<71v/
:3match Green /%>70v.*%<81v/
note that I used matchadd()
it supports max. 3 matches. If you need more, define syn pls.
add a screenshot
链接地址: http://www.djcxy.com/p/19138.html上一篇: 改变所选文字的颜色
下一篇: 基于列的ViM语法高亮显示