Skip to content

Instantly share code, notes, and snippets.

@rwstauner
Created June 22, 2011 15:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwstauner/1040278 to your computer and use it in GitHub Desktop.
Save rwstauner/1040278 to your computer and use it in GitHub Desktop.
highlight SQL syntax in a Perl heredoc
" ~/.vim/after/syntax/perl.vim
let s:bcs = b:current_syntax
unlet b:current_syntax
syntax include @SQL syntax/sql.vim
let b:current_syntax = s:bcs
" match optional, surrounding single or double quote and any whitespace in the heredoc name
syntax region perlHereDocSQL matchgroup=Statement start=+<<\(['"]\?\)\z(\s*SQL\s*\)\1+ end=+^\z1$+ contains=@SQL
@rwstauner
Copy link
Author

If your here doc isn't highlighting it may be that the sql syntax file isn't being processed (because the b:current_syntax is already set to something else). Turning it off works for me:

@petdance
Copy link

Perl 5 heredocs can't have leading whitespace before the terminator, so it should be

end=+^SQL$+

@rwstauner
Copy link
Author

Right, any whitespace would have to be included in the "start" match, and be matched exactly in the "end".

I was attempting to apply something else i had used to Ovid's (very simple, very specific) heredoc example.
I edited the whole thing to make it a bit more versatile. Surely still not 100% but maybe covers a few more cases now.

Anyway, thanks. Always better to be more correct. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment