我如何让 vim 突出显示多余的空白和所有选项卡?
我发现以下代码将突出显示所有不必要的空格,但我真的希望它也突出显示代码中的所有选项卡。我尝试了很多不起作用的变体,但我找不到一个可以同时完成这两个任务的正则表达式。有什么想法吗?
highlight RedundantWhitespace ctermbg=red guibg=red
match RedundantWhitespace /\s\+$\| \+\ze\t/
编辑:按请求添加示例:
好的,在下面的示例中,我使用 \t 表示制表符,使用 % 表示我希望 vim 以红色突出显示的尾随空格。
/tOh hi here is some text%%%%
/t/tHere is some indented text%%%
因此,在第一行,有 1 个选项卡的空格应以红色突出显示,4 个尾随空格应以红色突出显示。第二行有 2 个制表符和 3 个尾随空格以红色突出显示。
I found the following code that will highlight all unnecessary whitespace, but I really want it to also highlight all the tabs in my code. I played around with a lot of variations that didn't work but I couldn't find a regex that would do both. Any ideas?
highlight RedundantWhitespace ctermbg=red guibg=red
match RedundantWhitespace /\s\+$\| \+\ze\t/
Edit: adding samples by request:
Okay so in the samples below I am using \t to represent tab and % to represent a trailing whitespace that I want vim to highlight in red.
/tOh hi here is some text%%%%
/t/tHere is some indented text%%%
So on the first line there are 1 tab that should have their spaces highlighted in red and 4 trailing spaces to have highlighted in red. On the second line there are 2 tabs and 3 trailing whitespaces to have highlighted in red.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用
listchars
而不是语法突出显示。这对于所有文件类型都适用。您也可以使用listchars
来表示尾随空格,也可以对颜色进行混乱:请注意,此处的背景颜色和前景色是相同的,因此您最终会看到尾随空格和制表符的红色“块” 。
I'd recommend using
listchars
rather than syntax highlighting. This would work across the board for all file types. You can uselistchars
for trailing spaces too, and mess with the colours as well:Note that the background and foreground colours are the same here, so you end up seeing red "blocks" for trailing space and tabs.
来自您对另一个答案的评论:
这是否符合您的要求?
用人类的话来说,这是:
似乎选择了示例中的空格。
From your comment on another answer:
Does this do what you want?
In human terms, this is:
It seems to select the white space in your examples.
我认为你想使用
\zs
(对于“开始”)而不是\ze
(对于“结束”):这仍然只会突出显示前面有一个的选项卡或更多空间,不过。不确定这是否是您想要的。以下是突出显示所有选项卡的版本:
I think you want to use
\zs
(for "start") rather than\ze
(for "end"):That will still only highlight tabs that are preceded by one or more spaces, though. Not sure if that's what you want or not. Below is a version that will highlight all tabs: