Setting a Language for vim Syntax Highlighting

Setting a Language for vim Syntax Highlighting

VIM Logo
One can force the language for vim syntax highlighting with

:setf  language

Examples

For C:

:setf c

For PHP:

:setf php

For XML:

:setf xml

Update: An Alternative

In the comments below, Vladimir wrote:

Another way is :set filetype=language

Simple executing :set filetype will show current language used for syntax highlighting.

Thanks for the additional information. 🙂

Comments

  • om | Feb 4,2009

    Was looking for precisely this information, thanks.

    I Have some code in files without file extensions, so I need to manually specify the language otherwise there is no highlighting.

  • James Reuben Knowles | Feb 4,2009

    So did I. 🙂

    Glad this helped.

  • DF | Mar 12,2009

    Cheers, just what I needed!

  • James Reuben Knowles | Mar 12,2009

    Great! You’re welcome. 🙂

  • Shannon S. | Sep 1,2009

    Thanks for the info, spot on!

  • Braden | May 11,2010

    Thanks a bunch!

  • John M | Jan 25,2011

    over 2 years later, and still a good find! Thanks!

  • Jorge Medina | Feb 24,2011

    Thanks, I was just editing a xml config without xml headers or file extension so it wouldnt detect the syntax, :setf xml works.

  • Peter | Apr 8,2011

    Yaay!

  • Daniel | Apr 20,2011

    Thank you very much for this. Exactly what I needed.

  • Max | May 16,2011

    Thanks!

  • kumbhar shrikant | May 25,2011

    WOW !!!!
    Great help !!

  • kevin | Jul 26,2011

    Thanks for sharing!

  • Vladimir | Nov 28,2011

    Another way is :set filetype=language

    Simple executing :set filetype will show current language used for syntax highlighting.

  • kaewgb | Dec 1,2011

    Exactly what I wanted. Thanks 🙂

  • James Reuben Knowles | Dec 2,2011

    Thanks for the tip, Vladimir. I’ll update the post.

  • Leonardo | Feb 11,2012

    Thanks for the help it was very useful

    later

  • Antoine | Jun 8,2012

    Thanks !

    Really helpul when editing file in a web browser with, for example, “It’s all text” add-on (since the open file does not have specific extension, header , #!…) .

  • Dri | Feb 26,2013

    Thanks, “:setf diff” worked like a charm!

  • bienemaya | Mar 29,2013

    put this in .vimrc to make it stay:

    au BufRead,BufNewFile *.NEWFILETYPE set filetype=html

  • Patrick | Jun 24,2014

    This works great but if you switch to another buffer and back its gone again. Is there a way to get it to stick with the open buffer until its its closed?

  • Leave a Reply

    %d bloggers like this: