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 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 ...


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

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .