Define syntax region in multiple buffers via bufdo

19 views
Skip to first unread message

Edward Beach

unread,
Nov 16, 2012, 2:03:25 PM11/16/12
to vim...@googlegroups.com
If I execute the command 'syn region Region1 matchgroup=Highlight1 start=+(+ end=+)+' individually on three different buffers, the syntax region Region1 is properly defined in all three buffers.

However if I execute it via bufdo, like 'bufdo syn region Region1 matchgroup=Highlight1 start=+(+ end=+)+' the syntax region is missing on the last buffer.

I would like to define this region in all active buffers but I don't understand why bufdo is failing. Could somebody help?

Thanks!

Andy Wokula

unread,
Nov 16, 2012, 3:07:44 PM11/16/12
to vim...@googlegroups.com
:bufdo executes its arguments with ignored Syntax event. E.g. try
:bufdo set ei?
to convince yourself.

When :bufdo finishes, it fires the Syntax event to activate syntax
highlighting for the last (= current) buffer. This clears the syntax
highlighting that you just defined for that buffer.


Suggestion:

augroup MySyntax
au!
auSyntax * syn region Region1 matchgroup=Highlight1 start=+(+ end=+)+
augroup End


When defining these commands in the vimrc, I'd also make sure this is
installed after other Syntax autocmds:

augroup Vimrc
au!
au VimEnter * call s:AfterPlugin()
augroup End

func! s:AfterPlugin()
augroup MySyntax
au! Syntax * syn region Region1 matchgroup=Highlight1 start=+(+ end=+)+
augroup End
endfunc


A surrounding :augroup command is not required, but a good habit ...
makes it generally easier to filter and remove autocmds.

--
Andy
Reply all
Reply to author
Forward
0 new messages