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).
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.
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.
After making changes to file you need to reset the changes by executing following command.
# source /etc/profile OR # 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
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 Off Syntax Highlighting in VI
Latest posts by Ravi Saive (see all)
- How to Install GUI (Gnome 3) Using CD/DVD on RHEL/CentOS 7 - December 18, 2014
- Wine 1.7.33 (Development Version) Released – Install in RedHat and Debian Based Systems - December 13, 2014
- How to Enable RPMForge Repository in RHEL/CentOS 7.x/6.x/5.x - December 12, 2014