Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable syntax conceal only in certain contexts in Vim?

Tags:

syntax

vim

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=α

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 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="[ _]"

Thanks in advance!

like image 338
fozziethebeat Avatar asked May 07 '12 06:05

fozziethebeat


1 Answers

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

:syntax match scalaNiceKeyword '\(_\|\<\)\zsalpha\ze\(\>\|_\)' conceal cchar=α
like image 184
ib. Avatar answered Oct 17 '22 13:10

ib.