How to enable text colour in vi similar to vim in CentOS/RHEL

If you use vim text editor, you would have seen the colorful text mark-up. It helps a lot in case you are writing scripts.

By default vi editor does not have this feature enabled. Follow the steps below to enable the text colour feature in vi.

1. install vim-enhanced if not already installed.

# yum install vim-enhanced

2. Hash out the line containing “[ -n “$ID” -a “$ID” -le 200 ] && return“.

# vi /etc/profile.d/vim.sh

if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
  [ -x /usr/bin/id ] || return
  ID=`/usr/bin/id -u`
  #[ -n "$ID" -a "$ID" -le 200 ] && return  ### hash out this line
  # for bash and zsh, only if no alias is already set
  alias vi >/dev/null 2>&1 || alias vi=vim
fi

3. Logout and login again to see the text color using vi.

Related Post