How to enable VI and VIM Syntax Highlighting in Fedora / CentOS / RedHat

We will be needing root permissions to enable this feature.

Default view of vi/vim without syntax highlighting:


It would be a lot easier for developers to read / create programs if the codes they are writing are more distinct, so let’s enable syntax highlighting in our environment.


  1. Check whether our current version of vi supports syntax highlighting feature.
    We can use this commands to verify:

                [root@testserver ~]$vi --version

    You will see +syntax from the results if it is supported and -syntax if it’s not. If it is supported you can proceed to STEP # 5.

  2. Check if vim is installed and if it supports syntax highlighting.
    Use this command to verify:

                [root@testserver ~]$vim --version

    Again, you will see +syntax if supported and -syntax if it’s not. If it is supported you can go to STEP # 4.

  3. Install vim-enhanced package.
                [root@testserver ~]$yum install vim-enhanced

    Vim-enhanced is a very huge version which supports syntax highlighting, so you should see +syntax when you try to verify it using the command from STEP #2.

  4. Pointing vi to use vim using .bashrc file.
    This step is optional, just incase that you are more used to typing vi instead of vim.

                [root@testserver ~]$vi ~/.bashrc

    Append this line, then quit and save.

    alias vi=vim

    Reload .bashrc

                [root@testserver ~]$. ~/.bashrc
  5. Enable syntax highlighting.
    Create or update your .vimrc file.

    [root@testserver ~]$. vi ~/.vimrc

    Append these line:

                syntax on
  6. Check if Syntax highlighting is enabled.
    Here’s the output from my view:


TIP: You can also toggle syntax highlighting in vi/vim using :syntax on and :syntax off.

Leave a Reply

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