H ow do I turn on or off color syntax highlighting in vi or vim text editor on a Linux or Unix-like operating system?

Vim or vi is a text editor. It can be used to edit all kinds of plain text files, editing programs, and UNIX/Linux configuration files. Vim supports additional options and it includes a lot of enhancements above old good vi text editor. Syntax highlighting is nothing but a feature of vi/vim text editors that displays text, especially source code, in different colors and fonts according to the category of terms. The following instructions show you how to enable or disable syntax colors for VI/VIM text editor running on a Linux or Unix-like system.

Tutorial details
Difficulty level
Root privilegesNo
RequirementsLinux or Unix terminal
CategoryText Editor
Prerequisitesvim
OS compatibility*BSD • • • • WSL
Est. reading time4 minutes

How to enable vim syntax colors option

The permanent procedure is as follows for vim/vi:

  1. Edit the ~/.vimrc file by typing the command: vim ~/.vimrc
  2. Append the following option:
    syntax on
  3. Save and close the file
  4. Test it by running vim command: vim foo.sh

Let us see all steps in details for turning on or off color syntax highlighting under Linux, macOS and Unix-like system when using vim text editor.

Please note that on most Linux distro vi is a symbolic link to vim text editor.

Turn on color syntax highlighting in vim

Open a file, for example open existing file called file.c, enter:
$ vi file.c
Now press ESC key, type “: syntax on ” i.e. type as follows:
:syntax on
If above syntax failed to work, try (press Esc and then type):
:set syntax=on
Here is C source code editing while syntax highlighting is on in vi or vim:

Fig.01: Turn on or off color syntax highlighting in vi or vim

Fig.01: Turn on or off color syntax highlighting in vi or vim

Turn off color syntax highlighting in vim

To turn it back off, press ESC key, type : syntax off
:syntax off

How do I make the syntax highlighting permanent under vim?

You can edit ~/.vimrc file and add append vim command syntax on to it. This ensures that vim will start with color syntax highlighting option. First, use the cmd command to change to the current directory:
$ cd ~ $ vi .vimrc
Append the following line:
syntax on
Save and close the file. You should now be able to use vim to edit files with syntax on options.

How to set and use a vim color scheme

You can find installed color schemes in the following path:
/usr/share/vim/vim*/colors/
Use the ls command to list it:
$ ls -l /usr/share/vim/vim*/colors/
Sample outputs:

total 76
-rw-r--r-- 1 root root 2476 Jul 27 01:43 blue.vim
-rw-r--r-- 1 root root 2990 Jul 27 01:43 darkblue.vim
-rw-r--r-- 1 root root  548 Jul 27 01:43 default.vim
-rw-r--r-- 1 root root 2522 Jul 27 01:43 delek.vim
-rw-r--r-- 1 root root 2812 Jul 27 01:43 desert.vim
-rw-r--r-- 1 root root 1666 Jul 27 01:43 elflord.vim
-rw-r--r-- 1 root root 2452 Jul 27 01:43 evening.vim
-rw-r--r-- 1 root root 1958 Jul 27 01:43 industry.vim
-rw-r--r-- 1 root root 3555 Jul 27 01:43 koehler.vim
-rw-r--r-- 1 root root 2460 Jul 27 01:43 morning.vim
-rw-r--r-- 1 root root 2006 Jul 27 01:43 murphy.vim
-rw-r--r-- 1 root root 1037 Jul 27 01:43 pablo.vim
-rw-r--r-- 1 root root 2673 Jul 27 01:43 peachpuff.vim
-rw-r--r-- 1 root root 2904 Jul 27 01:43 README.txt
-rw-r--r-- 1 root root 1393 Jul 27 01:43 ron.vim
-rw-r--r-- 1 root root 2720 Jul 27 01:43 shine.vim
-rw-r--r-- 1 root root 2445 Jul 27 01:43 slate.vim
-rw-r--r-- 1 root root 1629 Jul 27 01:43 torte.vim
-rw-r--r-- 1 root root 1840 Jul 27 01:43 zellner.vim

To use torte color scheme type the following in vim text editor:
:colorscheme torte
Sample outputs:

How to turn on or off color syntax highlighting and colors in vim

Using a vim color scheme

Summary

Add command in your ~/.vimrc file:

vim CommandDescription/Purpose
syntax onEnabling vi/vim syntax colors
syntax offDisabling vi/vim syntax colors
colorscheme industrySpecifying a colorscheme called foo. Use ‘/usr/share/vim/vim*/colors/’ to find installed color scheme

Vim Syntax highlighting options

You can also use the following command that switches on syntax highlighting:
:syntax enable
Which basically execute the command:
:source $VIMRUNTIME/syntax/syntax.vim

More about turning on and of vim syntax highliting

Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn’t parse the whole file (to keep it fast), so the highlighting has its limitations. Lexical highlighting might be a better name, but since everybody calls it syntax highlighting we’ll stick with that. Vim supports syntax highlighting on all terminals. But since most ordinary terminals have very limited highlighting possibilities, it works best in the GUI version, gvim. See following tutorials:

When running vim, type the following option to read help about vim syntax highlighting (or see online help):
:help syntax

🥺

Was this helpful?

Please add a comment to show your appreciation or feedback.

CategoryList of Unix and Linux commands
AnsibleCheck version • Fedora • FreeBSD • Linux • Ubuntu 18.04 • Ubuntu • macOS
Archivingz commands
Backup ManagementDebian/Ubuntu • FreeBSD • RHEL
Database ServerBackup MySQL server • MariaDB Galera cluster • MariaDB TLS/SSL • MariaDB replication • MySQL Server • MySQL remote access
Download managerswget
Driver Management• lsmod
Documentationhelp • mandb • man • pinfo
Disk Managementdf • duf • ncdu • pydf
File Managementcat • cp • less • mkdir • more • tree
FirewallAlpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 • Ubuntu 24.04
KVM VirtualizationCentOS/RHEL 7 • CentOS/RHEL 8 • Debian 9/10/11 • Ubuntu 20.04
Linux Desktop appsChrome • Chromium • GIMP • Skype • Spotify • VLC 3
LXDBackups • CentOS/RHEL • Debian 11 • Fedora • Mount dir • Ubuntu 20.04 • Ubuntu 22.04
Modern utilitiesbat • exa
Network ManagementMonitoring tools • Network services • RHEL static IP • Restart network interface • nmcli
Network UtilitiesNetHogs • dig • host • ip • nmap • ping
OpenVPNCentOS 7 • CentOS 8 • Debian 10 • Debian 11 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Power Managementupower
Package Managerapk • apt-get • apt • yum
Processes Managementbg • chroot • cron • disown • fg • glances • gtop • iotop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searchingag • egrep • grep • whereis • which
Shell builtinscompgen • echo • printf
System Managementreboot • shutdown
Terminal/sshsshpass • tty
Text processingcut • rev
Text Editor6 Text editors • Save and exit vim
User Environmentexit • who
User Informationgroups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • w
User Management/etc/group • /etc/passwd • /etc/shadow • chsh
Web Server• • • Nginx Security •
WireGuard VPNAlpine • Amazon Linux • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 • qrencode