Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have files containing code within a prefix-based structure, such as:

perl: sub abc {
perl:     return "def";
perl: }

I'd like to be able to highlight the perl as normal. i.e. ignore the perl: prefix. Using the built-in help for syntax I have:

syntax include @Perl syntax/perl.vim
syntax region testPerl start=/^perl: \?/ end=/$/ contains=testPerlContinue,@Perl
syntax match testPerlContinue "\$perl:" contained

However, as expected, this treats the perl: prefix as part of the code; an obvious example of this breaking is where a Perl 'quote' carries over several lines.

Is it possible to ignore prefixes within Vim when syntax highlighting?

share|improve this question
It is very unlikely this will be easy, if it's even possible. For example, if you look at the perl.vim syntax file you'll find at least a few patterns that "anchor" to the beginning of the line. – Heptite Jan 10 '12 at 17:32
Thanks for pointing out the anchoring problem. It certainly indicates it's not possible. The alternative is to pre-process the file into regions more conducive to syntax highlighting, then post-process it back to the original format. I'd ideally like to avoid that for the 'simple' task of editing a file though. – Unk Jan 11 '12 at 10:40

You must log in to answer this question.

Browse other questions tagged .