Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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.