Monday, 15 April 2013

vim - How can I set a global syntax rule that takes precedent over a file specific one? -



vim - How can I set a global syntax rule that takes precedent over a file specific one? -

i want unexpected characters have different background color usual ones. set next highlighting rule in .vimrc:

syntax match notprintableascii "[^\x20-\x7f]" hi notprintableascii ctermbg=236

this words great files, doesn't work has filetype-specific syntax rules.

where should set works file types?

the fact works due these 2 things:

it matches toplevel elements aren't yet contained in syntax group. add together containedin=all embed everywhere. note may disrupt existing syntax. the definition in ~/.vimrc early; syntax script override yours. prepend :autocmd syntax * :syntax command, , place after :syntax on in ~/.vimrc.

you need 2 entries, 1 files without filetype-specific syntax rules (e.g. files without extension) , 1 files syntax rules (e.g. .py files):

syntax on " files don't have filetype-specific syntax rules syntax match notprintableascii "[^\x20-\x7f]" " files have filetype-specific syntax rules autocmd syntax * syntax match notprintableascii "[^\x20-\x7f]" containedin=all hi notprintableascii ctermbg=236

vim

No comments:

Post a Comment