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.

20 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

  17. Antoine says:

    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 , #!…) .

  18. Dri says:

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

  19. bienemaya says:

    put this in .vimrc to make it stay:

    au BufRead,BufNewFile *.NEWFILETYPE set filetype=html

Leave a Reply