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. 🙂

21 thoughts on “Setting a Language for vim Syntax Highlighting

  1. om

    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. Vladimir

    Another way is :set filetype=language

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

  3. Antoine

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

  4. bienemaya

    put this in .vimrc to make it stay:

    au BufRead,BufNewFile *.NEWFILETYPE set filetype=html

  5. Patrick

    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