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 versionFedoraFreeBSDLinuxUbuntu 18.04UbuntumacOS
Archivingz commands
Backup ManagementDebian/UbuntuFreeBSDRHEL
Database ServerBackup MySQL serverMariaDB Galera clusterMariaDB TLS/SSLMariaDB replicationMySQL ServerMySQL remote access
Download managerswget
Driver Managementlsmod
Documentationhelpmandbmanpinfo
Disk Managementdfdufncdupydf
File Managementcatcplessmkdirmoretree
FirewallAlpine AwallCentOS 8OpenSUSERHEL 8Ubuntu 16.04Ubuntu 18.04Ubuntu 20.04Ubuntu 24.04
KVM VirtualizationCentOS/RHEL 7CentOS/RHEL 8Debian 9/10/11Ubuntu 20.04
Linux Desktop appsChromeChromiumGIMPSkypeSpotifyVLC 3
LXDBackupsCentOS/RHELDebian 11FedoraMount dirUbuntu 20.04Ubuntu 22.04
Modern utilitiesbatexa
Network ManagementMonitoring toolsNetwork servicesRHEL static IPRestart network interfacenmcli
Network UtilitiesNetHogsdighostipnmapping
OpenVPNCentOS 7CentOS 8Debian 10Debian 11Debian 8/9Ubuntu 18.04Ubuntu 20.04
Power Managementupower
Package Managerapkapt-getaptyum
Processes Managementbgchrootcrondisownfgglancesgtopiotopjobskillallkillpidofpstreepwdxtimevtop
Searchingagegrepgrepwhereiswhich
Shell builtinscompgenechoprintf
System Managementrebootshutdown
Terminal/sshsshpasstty
Text processingcutrev
Text Editor6 Text editorsSave and exit vim
User Environmentexitwho
User Informationgroupsidlastcommlastlid/libuser-lidlognamemembersuserswhoamiw
User Management/etc/group/etc/passwd/etc/shadowchsh
Web Server• • • Nginx Security
WireGuard VPNAlpineAmazon LinuxCentOS 8Debian 10FirewallUbuntu 20.04qrencode