Skip to content

Instantly share code, notes, and snippets.

@todesking
Last active September 27, 2020 09:22
Show Gist options
  • Save todesking/8f32b7042439752dc9d6124c3bd68a38 to your computer and use it in GitHub Desktop.
Save todesking/8f32b7042439752dc9d6124c3bd68a38 to your computer and use it in GitHub Desktop.
syntax-region's odd behavior
syntax clear
syntax match expr_name /\K\k*/ nextgroup=B
syntax region outer
\ start=/(/ end=/)/
\ contains=inner
syntax region inner
\ start=/(/ end=/)/
\ contains=expr_name
\ contained
highlight outer guifg=#00ffff
highlight inner guifg=#ff0000
highlight expr_name guifg=#ff00ff
" Expected: ((aaa))
" ^ ^ outer
" ^ ^ inner
" ^^^ expr_name
" Actual: ((aaa))
" ^^ ^ inner
" ^^^ expr_name
" ^ outer
" Using matchgroup to avoid above behavior.
" :help :syn-contains says:
" > The contained groups will also match in the start and end patterns of a
" > region. If this is not wanted, the "matchgroup" argument can be used
" > |:syn-matchgroup|.
syntax clear
syntax match expr_name /\K\k*/ nextgroup=B
syntax region outer
\ matchgroup=outer_parenthesis
\ start=/(/ end=/)/
\ contains=inner
syntax region inner
\ matchgroup=inner_parenthesis
\ start=/(/ end=/)/
\ contains=expr_name
\ contained
highlight outer_parenthesis guifg=#00ffff
highlight inner_parenthesis guifg=#ff0000
highlight expr_name guifg=#ff00ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment