Vim 语法着色:如何仅突出显示长行? [英] Vim syntax coloring: How do I highlight long lines only?

查看:19
本文介绍了Vim 语法着色:如何仅突出显示长行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 vim 为我着色长"行.以 80 列为例,我想突出显示超过该长度的行.这大致是我认为 .vimrc 文件应该包含的内容,尽管它 (1) 不起作用,并且 (2) 使用 Perl 的正则表达式语法来说明我的观点,因为我不太了解 Vim:

I would like vim to color "long" lines for me. Using 80 columns as an example, I would like to highlight lines that exceed that length. Here is roughly what I think the .vimrc file should contain, although it (1) doesn't work, and (2) uses Perl's regex syntax to illustrate my point, because I don't know Vim's well enough:

...
highlight Excess ctermbg=0
au Syntax * syn match Excess /.{80,}$/
...

这(至少在我看来)应该标记超过 80 列的行.理想情况下,我希望能够仅为超过 80 列的行部分着色,因此如果一行是 85 列,那么第 81 到第 85 列将被突出显示.

This (in my mind at least) should mark lines that exceed 80 columns. What I would ideally like is the ability to color only the part of the line that exceeds 80 columns, so if a line is 85 columns, then the 81st through the 85th columns would be highlighted.

我确信 Vim 可以做到这一点,只是不是由我掌舵.

I'm sure Vim can do this, just not with me at the helm.

推荐答案

我需要自动命令来为我工作:

I needed the autocomand to work for me:

augroup vimrc_autocmds
  autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#111111
  autocmd BufEnter * match OverLength /\%75v.*/
augroup END

如果您的目标是平均 80 列,也喜欢使用 75 的想法.

Also like the idea of using 75 if you are aiming at 80 columns in average.

取自:

http://blog.ezyang.com/2010/03/vim-textwidth/

没有BufEnter 失败的可能原因:highlight + match 只能使用一次.多次使用意味着旧的被覆盖.如何添加多个亮点

Possible reason why it fails without BufEnter: highlight + match can only be used once. Multiple usage means that old ones are overridden. How to add multiple highlights

这篇关于Vim 语法着色:如何仅突出显示长行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆