最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何仅在 Vim 中的某些上下文中启用语法隐藏?

网站源码admin48浏览0评论
本文介绍了如何仅在 Vim 中的某些上下文中启用语法隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想隐藏名称基于希腊符号的变量并将它们转换为它们的 Unicode 等效符号,类似于 vim-cute-python 有效.例如,我有这个:

I want to conceal variables with names based on Greek symbols and turn them into their Unicode equivalent symbol, similarly to how vim-cute-python works. For instance, I have this:

syntax match scalaNiceKeyword "alpha" conceal cchar=α

定义在一个文件中,用于隐藏在 Scala 文件中,效果很好,只是过于激进.如果我写alphabet,它就会被隐藏起来成为αbet,这显然是错误的.

defined in a file for concealing within Scala files which works great except that it's overly aggressive. If I write alphabet it then gets concealed to become αbet, which is noticeably wrong.

如何修改或扩展此隐藏语句,使其仅隐藏与 [ _]alpha[ _] 匹配的关键字?换句话说,我想要以下转换:

How can I modify or expand this conceal statement so that it only conceals keywords that match [ _]alpha[ _]? In other words, I want the following conversions:

alpha_1 => α_1
alpha => α
alphabet => alphabet

注意:这类似于 这个问题,但是它似乎稍微复杂一些,因为我要匹配的组环境是空格和下划线.天真地定义如下语法区域会导致各种错误:

Note: This is similar to this question, however it seems like it's slightly more complicated since the group environment I want to match is spaces and underscores. Naively defining a syntax region like the following makes things all kinds of wrong:

syn region scalaGreekGroup start="[ _]" end="[ _]"

提前致谢!

推荐答案

修改模式以仅匹配由单词分隔的名称边界或下划线:

Modify the pattern to match only the names delimited by word boundaries or underscores:

:syntax match scalaNiceKeyword '\(_\|\<\)\zsalpha\ze\(\>\|_\)' conceal cchar=α

这篇关于如何仅在 Vim 中的某些上下文中启用语法隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

发布评论

评论列表(0)

  1. 暂无评论