Enable syntax highlighting in Vim

Vim can perform syntax highlighting for various file formats. You can enable it with these steps if it's not currently enabled;

  1. Make sure full version of Vim with support for syntax highlighting is installed.
  2. Manually enable syntax highlighting while in Vim.
    1. Enter command mode by pressing Esc.
    2. Type :syntax on|off and press Enter.
      :syntax on
  3. Manually set syntax for file if required.
    1. Enter command mode by pressing Esc
    2. Type :set syntax=<filetype> and press Enter.
      :set syntax=php
    3. To view the list of supported file types, issue :echo getcompletion while also in the command mode.
      :echo getcompletion('' 'filetype')
  4. Permanently enable syntax highlighting by adding :syntax on in your ~/.vimrc file.

Sign up for Vim Masterclass and many other great courses on Udemy to learn more.

Vim Masterclass

Mastering the vi and Vim Editors on the Linux, Unix, Mac, and Windows Operating Systems!

Written by Mohd Shakir Zakaria.

Last updated on 2019-02-12.