Did You Know?
Donate to TecMint

LFCS - Linux Foundation Certified SysAdmin - Exam Preparation Guide

VI Editor Syntax Highlighting with VIM on RHEL / CentOS / Fedora

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

This how-to guide covers how to install and enable Syntax Highlighting in VI using VIM (enhanced) text editor on RHEL 6.3/6.2/6.1/6/5.8/5.6, CentOS 6.3/6.2/6.1/6/5.8/5.6 and Fedora 17,16,15,14,13,12. By default on all Linux systems only have minimal version of VI with plain text editor and that works perfectly for normal users, but for programmers and developers it becomes very difficult to identify the code parameters. To enable Syntax Highlighting in VI, we required enhanced version of VI editor called Vim (Vi IMproved).

Syntax-Highlighting in VI Editor

Syntax Highlighting in VI Editor on Linux

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn’t show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file. By default VIM works on all Linux terminals, but some terminals have minimal highlighting capabilities to run.

VIM has another great feature that enable us to Turn Off or Turn On syntax highlighting using option syntax on and syntax off.

How to Install VIM

Most of the Linux system already included VIM package, if not then install it using YUM tool.

# yum -y install vim-enhanced

How to Enable Syntax Highlighting in VI and VIM

To enable Syntax Highlighting feature in VI editor, open the file called /etc/profile.

# vi /etc/profile

Add the alias function to VI by pointing to VIM in /etc/profile file. This file is used to set alias functions globally.

alias vi=vim

If you would like to set user specific aliases and functions, then you need to open the file .bashrc under user directory.

# vi /home/tecmint/.bashrc

Add the alias function. For example we set alias for tecmint user.

alias vi=vim

After making changes to file you need to reset the changes by executing following command.

# source /etc/profile
# source /home/tecmint/.bashrc

Test Syntax Highlighting in VI

Open any example code of file with vi editor. By default Syntax Highlighting is automatically turned on in /etc/vimrc file.

Example of Syntax Highlighting in VI

Syntax Highlighting in VI

Syntax Highlighting in VI Editor

Turn On or Turn Off Syntax Highlighting in VI

You can Turn On or Turn Off syntax highlighting by pressing ESC  button and use command as :syntax on and :syntax off in Vi editor. Refer example screenshots.

Turn On Syntax Highlighting in VI

Turn On VI Syntax Highlighting

Turn On Syntax Highlighting in Vi

Turn Off Syntax Highlighting in VI

Turn Off Syntax Highlighting

Turn Off Syntax Highlighting in VI

Ravi Saive

Owner at TecMint.com
Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.

Your name can also be listed here. Work as a Paid freelancer/writer at TecMint.
Download Free eBooks
Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

4 Responses

  1. David Hughes says:

    Can’t you just type ‘vim’? I realise it’s an extra letter, and everything, but…

  2. David Sehguh says:

    vi is a symbolic link to vim if you have vim installed.

  3. David Sehguh says:

    :set syntax! will toggle the highlighting on and off.

    :set syntax? will let you know if syntax highlighting is off or on.

  4. hh says:

    i use centos use follow this but not working

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.