问题
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