vim中光标下的空白
我最近看到了这个演示。我的问题是:vim 中如何将光标下的空白字符显示为点(例如红色)。
I recently saw this demo. My question is: how is it possible in vim to show whitespace characters under the cursor as dots (in red for example).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为这显示了光标下的空间;我认为它显示了尾随空格。这是由
listchars
选项控制的,该选项控制list
的行为。要打开它,请使用:颜色由
hl-SpecialKey
组确定;你可以这样改变它:I don't think that's showing space under the cursor; I think it's showing trailing spaces. This is controlled by the
listchars
option, which controls the behavior oflist
. To turn it on, use:The color is determined by the
hl-SpecialKey
group; you can change it like this:突出显示光标前后的空白
适用于 gvim 的正常模式。要使其在终端 vim 中工作,请将 guibg 更改为 ctermbg。如果您也希望它处于插入模式,请将 au CursorMoved 更改为
虽然在这种情况下您需要调整正则表达式,因为在输入插入时该正则表达式会错误地匹配光标右侧的非空白字符模式。
在正则表达式中 \%# 匹配当前光标位置。我必须在它后面使用 . 因为如果没有它它就无法匹配光标右侧的空白。
Highlight whitespace before and after the cursor
That works for normal mode with gvim. To make it work in terminal vim change the guibg to ctermbg. If you want it also in insert mode, change
au CursorMoved
toAlthough in that case you'd need to tweak the regex since that one matches erroneously non-whitespace characters to the right of the cursor when entering insert mode.
In the regex \%# matches the current cursor position. I had to use . after it since it wouldn't match whitespace to the right of the cursor without it.