使用非标准配色方案突出显示 80 多个字符

发布于 2024-12-10 12:57:14 字数 510 浏览 0 评论 0原文

在 vim 中,我试图让它在超过 80 个字符时突出显示我的屏幕(我是内核开发人员,这是内核代码的要求)。我在 .vimrc 文件中使用以下内容来执行此处

highlight OverLength ctermbg=red ctermfg=white guibg=#59292
match OverLength /\%81v.\+/

建议的操作: Vim 80 列布局问题

但是,我是色盲,因此我无法使用默认的颜色方案并看到屏幕上的文本,因此我使用 :colorscheme 更改我的默认颜色方案还有果仁蛋糕。但是,颜色方案似乎覆盖了我的突出显示(当我没有指定颜色方案时,它会突出显示,而在指定时则不会)。

有谁知道如何通过 colorscheme 更改来实现此功能?感谢您的帮助,

In vim I am trying to have it highlight my screen when it goes over 80 characters (I am a kernel developer and this is a requirement for kernel code). I am using the following in my .vimrc file to do this

highlight OverLength ctermbg=red ctermfg=white guibg=#59292
match OverLength /\%81v.\+/

which was suggested here: Vim 80 column layout concerns

However, I am colorblind and as a result I cannot use the default colorscheme and see the text on the screen so I change my default colorscheme using :colorscheme torte as well. However, it appears that the colorscheme overrides the highlighting on me (it highlights fine when I don't have the colorscheme specified, and doesn't when it is specified).

Does anyone have any ideas on how to make this work with the colorscheme change? Thanks for your help,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

财迷小姐 2024-12-17 12:57:14

如果您有 Vim 7.3+,您可以使用:

:set colorcolumn=81

If you have Vim 7.3+ you can use:

:set colorcolumn=81
情感失落者 2024-12-17 12:57:14

这是因为大多数配色方案的开头都有这一行:

hi clear

这会清除创建的所有突出显示组(您创建了 OverLength)。这很好,因为没有颜色方案已设置所有内容,并且先前使用的方案中的颜色可能仍然出现。

为了解决这个问题,不要创建一个新组,而是将此模式匹配为 Error,它是默认的 Vim 组,将出现在每个配色方案中。只需将两行更改为一:

match Error /\%81v.\+/

That's because most color schemes have this line in their beginning:

hi clear

This clear all highlighting groups created (you created OverLength). This is good, because no colorscheme has every thing set, and colors from the previous scheme used could remain appearing.

To solve, instead of creating a new group, match this pattern as Error which is a default Vim group, will be present in every color scheme. Change your two lines by one simply:

match Error /\%81v.\+/
失而复得 2024-12-17 12:57:14

您可以使用 Colorscheme 事件来定义 OverLength 组:

augroup AddOverLength
    autocmd!
    autocmd ColorScheme * :highlight OverLength ctermbg=red ctermfg=white guibg=#59292
augroup END

请注意,您必须在定义后将所有对 :colorscheme 的调用放在 vimrc 中,或者使用显式启动此事件:doautocmd AddOverLength ColorScheme

You can use Colorscheme event to define OverLength group:

augroup AddOverLength
    autocmd!
    autocmd ColorScheme * :highlight OverLength ctermbg=red ctermfg=white guibg=#59292
augroup END

Note that you must either put all calls to :colorscheme that happen in your vimrc after this definition or explicitely launch this event by using :doautocmd AddOverLength ColorScheme.

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