Vim syntax conceal in context

守給你的承諾、 提交于 2019-12-23 09:24:06

问题


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. So for instance, I have this

syntax match scalaNiceKeyword "alpha" conceal cchar=α

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. How can I modify/expand this conceal statement so that it only conceals keywords that match "[ _]alpha[ _]", i.e. 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="[ _]"

Thanks in advance!


回答1:


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

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



回答2:


there's a script called unilatex.vim which defines imaps to do \alpha => α on opening/writing and backconversion on saving. I am using it for latex code and have modified it to drop backconversion as my latex compiler is able to do unicode right. I don't know if scala source code can be unicode, but if it can be you might have a look at my version.



来源:https://stackoverflow.com/questions/10477857/vim-syntax-conceal-in-context

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!