vim 隐藏多个字符
实际上我想在 haskell 文件中显示 ->
和 →
(箭头后面有一个空格)。但我的印象是隐藏机制只能用一个字符替换 ->
。不良的效果是视觉上不良的压痕。
有办法实现这一点吗?
谢谢。
编辑:实际上我使用这个(来自 haskell.vim
(隐藏增强)插件)
syntax match hsNiceOperator "<-" conceal cchar=←
Actually I'd like to display ->
with →
(there is a space after the arrow) in haskell files. But I have the impression the conceal mechanism only work to replace ->
by one character. An undesirable effect is visually bad indentation.
Is there a way to achieve this?
Thanks.
Edit: Actually I use this, (from haskell.vim
(conceal enhancement) plugin)
syntax match hsNiceOperator "<-" conceal cchar=←
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 C 中所做的正是您想要的。诀窍是单独隐藏每个字符,如下所示:
不幸的是,您可能会发现 ArrowHead 或 ArrowTail 在 ArrowFull 之外匹配。这是因为现有语法规则使用
contains=ALLBUT,...
或类似的内容。为了在 C 中解决这个问题,我将 ArrowTail 和 ArrowHead 添加到 cParenGroup 集群中,这似乎可以防止出现任何问题。
您可能需要为 Haskell 做类似的事情。
因为我根本不使用隐藏功能,所以我告诉 Vim 继续并始终“隐藏”箭头:
顺便说一句,如果您不喜欢隐藏字符的默认颜色,您可以像这样更改它们:
I do exactly what you want in C. The trick is to conceal each character separately, like so:
You might find that ArrowHead or ArrowTail gets matched outside an ArrowFull, unfortunately. This is because existing syntax rules use
contains=ALLBUT,...
or something similar.To fix this in C, I added ArrowTail and ArrowHead to the cParenGroup cluster, which seems to prevent any problems.
You may need to do something similar for Haskell.
Since I don't use the conceal feature at all otherwise, I tell Vim to go ahead and "conceal" the arrows ALL the time:
BTW if you don't like the default colors for the conceal chars, you can change them like this:
超级老的问题,但如果其他人试图解决这个问题,我已经成功地完成了以下操作:
matchadd
的第二个参数是
。查看:help pattern
告诉我们,模式
是一个或多个由\|
分隔的分支
,并且一个branch
是一个或多个由\&
分隔的concat
。从文档中:“[abranch
] 匹配最后一个concat
,但前提是所有前面的concat
也在同一位置匹配。”因此,在第一次调用中,我们指定一个具有一个分支的模式(没有
\|
值),由两个concat
组成。第一个concat
匹配完整箭头,第二个匹配箭头的第一个字符。因此,最后一个concat
是<
,它是所有被视为隐藏参数匹配的内容,但这仅在<
时匹配。 code> 出现在<-
中。第二次调用给出了一个带有一个branch
和一个concat
的pattern
。该模式以<
开头,但使用zero-width
原子\zs
重置匹配,该原子会重置下一个字符的匹配,-
,用空格隐藏。hi Conceal
只是突出显示。在我的测试中,
<
本身不会变成←
,而-
本身不会变成空格。希望这对某人有帮助:)
Super-old question, but in case anyone else is trying to figure this out, I have had success with the following:
The second argument of
matchadd
is<pattern>
. Looking at:help pattern
tells us that apattern
is one or morebranches
separated by\|
, and abranch
is one or moreconcats
separated by\&
. From the docs: "[abranch
] matches the lastconcat
, but only if all the precedingconcats
also match at the same position."So in the first call we specify a
pattern
with one branch (there are no\|
values), made of twoconcats
. The firstconcat
matches the full arrow, and the second matches the first character of the arrow. Thus, the lastconcat
is the<
which is all that is taken as the match for the conceal parameter, but this only matches if the<
appears in a<-
. The second call gives apattern
with onebranch
and oneconcat
. The pattern begins with the<
but the match is reset with thezero-width
atom\zs
which resets the match at the next character, the-
, which is concealed with a space. Thehi Conceal
is just highlighting.In my testing
<
by itself doesn't get turned into←
and-
by itself isn't turned into a space.Hope this helps someone :)