vim中光标下的空白

发布于 2024-08-29 03:28:28 字数 153 浏览 2 评论 0原文

我最近看到了这个演示。我的问题是: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

话少情深 2024-09-05 03:28:28

我不认为这显示了光标下的空间;我认为它显示了尾随空格。这是由 listchars 选项控制的,该选项控制 list 的行为。要打开它,请使用:

set list
set listchars=trail:·

颜色由 hl-SpecialKey 组确定;你可以这样改变它:

hi SpecialKey ctermfg=Red

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 of list. To turn it on, use:

set list
set listchars=trail:·

The color is determined by the hl-SpecialKey group; you can change it like this:

hi SpecialKey ctermfg=Red
最好是你 2024-09-05 03:28:28

突出显示光标前后的空白

highlight FooBar guibg=#80a0ff
au CursorMoved * :match FooBar /\s*\%#.\s*/

适用于 gvim 的正常模式。要使其在终端 vim 中工作,请将 guibg 更改为 ctermbg。如果您也希望它处于插入模式,请将 au CursorMoved 更改为

au CursorMoved,CursorMovedI,InsertEnter

虽然在这种情况下您需要调整正则表达式,因为在输入插入时该正则表达式会错误地匹配光标右侧的非空白字符模式。

在正则表达式中 \%# 匹配当前光标位置。我必须在它后面使用 . 因为如果没有它它就无法匹配光标右侧的空白。

Highlight whitespace before and after the cursor

highlight FooBar guibg=#80a0ff
au CursorMoved * :match FooBar /\s*\%#.\s*/

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 to

au CursorMoved,CursorMovedI,InsertEnter

Although 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文