You are on page 1of 5

VI Editor Syntax Highlighting with VIM on RHEL / CentOS / Fedora 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.6and 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 on Linux VIM is an alternative and advanced version of VI editor that enables Syntax highlightingfeature in VI. Syntax highlighting means it can show some parts of text in another fonts andcolors. VIM doesnt 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, called /etc/profile. # vi /etc/profile

open

the

file

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

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 Syntax Highlighting in Vi Turn Off Syntax Highlighting in VI

Turn Off Syntax Highlighting in VI

You might also like