Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know how to set up features using :autocmd for specific file extensions:

Eg. ~/.vim/ftplugin/xml.vim

augroup xml
    au BufEnter *.xml call Setup_XML_Menu()
    au BufLeave *.xml call Destroy_XML_Menu()
augroup END

Never mind whatSetup_XML_Menu()does - the point is I'm setting and resetting configuration when I enter or leave an XML buffer.

But is there a way to apply an autocommand for a particular filetype instead?

If I enter a buffer named *.xml, the BufEnter autocmd kicks in as I expect.
But I'd like this to happen when I enter any buffer that has filetype=xml

So if I enter a buffer named server.wsdl (assume I've already arranged for this buffer's filetype to be xml), I'd like the XML autocmd to be applied there too, without configuring autocommands for every conceivable XML file extension.

I hoped I could have something like:

au BufEnter xml call ...

or

au BufEnter filetype xml call ...

But these don't work (the first example only applies to a buffer named 'xml').

The other possibility I considered: au FileType xml ... only applies when I explicitly change the filetype of the buffer - I want the settings to be applied and removed when I hop in and out of particular buffer windows.

Am I asking too much?

share|improve this question

1 Answer 1

You could do something like au BufEnter * if &ft ==# 'xml' | commands | endif

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.