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'm using vim to browse through some log files (the file extension is .log) which contain a lot of XML.

How can I turn on XML syntax highlighting after opening the file? Of course, I don't actually want to associate XML syntax highlighting with all log files.

share|improve this question
up vote 7 down vote accepted

The command you want is ":setfiletype". For example:

:setf xml

See ":help :setfiletype".

share|improve this answer
Beautiful, this is exactly what I was looking for. Thanks! – Mansoor Siddiqui Jan 27 '12 at 22:42

You can place this in your ~/.vimrc file as well

au BufNewFile, BufRead *.extension_name set filetype=xml

Replace extension_name with the extension you want, reopen vim, and you will see xml syntax highlight.

share|improve this answer
This didn't work for me, this answer did work: autocmd BufEnter *.extension_name :setlocal filetype=xml – agold Dec 22 '15 at 16:18
It should be noted that this will cause all .extension_name files to be treated as the given filetype, which is behavior specifically mentioned as not wanted in the question. Still, potentially useful to others, so no downvote from me. – 8bittree Apr 27 at 16:28

Expanding on @RubyFanatic answer, what worked for me was (in vim's command mode):

au BufNewFile,BufRead *.extension_name setf xml
share|improve this answer

You must log in to answer this question.

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