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 the whole file but has 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 enables 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/rootadminz/.bashrc
Add the alias function. For example, we set alias for rootadminz 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/rootadminz/.bashrc
Test Syntax Highlighting in Vi Editor
Open any example code of file with vi editor. By default Syntax, Highlighting is automatically turned on in /etc/vimrc
file.
Turn On or Turn Off Syntax Highlighting in VI
You can Turn On or Turn Off syntax highlighting by pressing ESC button and use the command as syntax on
and syntax off
in Vi editor.