仅针对前导空格通过列表字符显示“空格"字符 [英] Show 'space' character via listchars only for leading spaces
问题描述
是否可以在 Vim 中使用我的编辑器(编辑 .c
和 .h
文件时),通过 listchars
显示,一个特殊的字符仅用于前导空格字符?
Is it possible in Vim to have my editor (when editing .c
and .h
files), show via listchars
, a special character only for leading space characters?
我发现一个单独的帖子指出,从 7.4 版开始,Vim 现在支持通过 listchars
突出显示所有空格字符.这是我当前的 listchars
变量:
I found a separate post that noted, as of version 7.4, Vim now supports highlighting all space characters via listchars
. Here's my current listchars
variable:
set list listchars=tab:>-,trail:.,extends:>,precedes:<,space:.
这是它在我的屏幕上的显示效果:
And here is a render of how it appears on my screen:
但是,我希望它看起来像这样(如下),其中只有 leading 空格通过 listchars
呈现,并且缩进相关空格之后出现的空格不是呈现.即:
However, I would like it to appear like so (below), where only leading spaces are rendered via listchars
, and spaces occurring after indentation-related spaces are not rendered. ie:
是否有一种简单的方法可以通过配色方案或 .vimrc
更改来实现此目的?
Is there a simple way to accomplish this, either via color scheme or .vimrc
changes?
图像差异,以防由于低对比度而导致差异不明显:
Image diff in case the difference isn't obvious due to low contrast:
推荐答案
我认为 linechars
不会帮助你,但这个亮点可能会有所帮助:
I don't think that linechars
will help you, but this highlight might help:
highlight WhiteSpaceBol guibg=lightgreen
match WhiteSpaceBol /^ \+/
更改您最喜欢的配色方案.
Change the color scheme for whatever you like best.
如果你坚持要花哨的·
,你可以通过一些技巧来获得它们:
If you insist on having the fancy ·
you can get them with a bit of a hack:
set listchars=space:·
highlight WhiteSpaceBol guifg=blue
highlight WhiteSpaceMol guifg=white
match WhiteSpaceMol / /
2match WhiteSpaceBol /^ \+/
现在,只有起始的 ·
是可见的!(将 white
更改为您用作背景的任何颜色,将 blue
更改为您选择的颜色).
Now, only the starting ·
are visible! (change the white
for whatever color you use as background and blue
with the color of your choice).
注意:如果您使用控制台 Vim,请将 guibg
替换(或添加)为 ctermbg
和适当的颜色.
NOTE: If you use the console Vim, replace (or add) guibg
with ctermbg
and the proper colors.
这篇关于仅针对前导空格通过列表字符显示“空格"字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!