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

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

17 Responses to Setting a Language for vim Syntax Highlighting

  1. om says:

    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.

  2. So did I. :)

    Glad this helped.

  3. DF says:

    Cheers, just what I needed!

  4. Great! You’re welcome. :)

  5. Shannon S. says:

    Thanks for the info, spot on!

  6. Braden says:

    Thanks a bunch!

  7. John M says:

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

  8. Jorge Medina says:

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

  9. Daniel says:

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

  10. Max says:

    Thanks!

  11. WOW !!!!
    Great help !!

  12. kevin says:

    Thanks for sharing!

  13. Vladimir says:

    Another way is :set filetype=language

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

  14. kaewgb says:

    Exactly what I wanted. Thanks :)

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

  16. Leonardo says:

    Thanks for the help it was very useful

    later

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">