Fundamentals 8 min read

Transform Your Vim Experience: Master Syntax Highlighting and Color Schemes

This guide walks you through installing Vim, enabling and disabling syntax highlighting, switching and persisting color schemes, customizing highlight groups, and tailoring language‑specific highlighting, all with clear commands and visual examples for a richer editing workflow.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Transform Your Vim Experience: Master Syntax Highlighting and Color Schemes

When using powerful IDEs, syntax elements are highlighted with distinct colors, making code easier to read. Vim, by default, shows plain black‑on‑white text, but it hides many useful features for customizing syntax highlighting.

First, ensure Vim is installed (Ubuntu includes it by default). If not, install it:

$ sudo apt-get install vim

Check the installed version:

$ vim -version

Create a sample login.sh Bash script to demonstrate editing:

#!/bin/bash

echo "Type your username"
read username
echo "Type your password"
read password

if [[ ($username == "admin" && $password == "secret") ]]; then
  echo "Authorized user"
else
  echo "Unauthorized user"
fi

Open the file with Vim:

$ vim login.sh

Enable/Disable Syntax Highlighting

Some distributions enable syntax highlighting by default; if not, press ESC and type :syntax on to enable it:

:syntax on

To turn it off, press ESC and type :syntax off:

:syntax off

Permanent Enable/Disable Syntax Highlighting

Temporary toggles disappear when the file is closed. To make the setting permanent, edit .vimrc:

$ sudo vim ~/.vimrc

Add syntax on (or syntax off) and save with :wq:

syntax on
:wq

Change Color Scheme

Vim ships with many color schemes located in /usr/share/vim/vim*/colors/. List them with:

$ ls -l /usr/share/vim/vim*/colors/

To apply a scheme temporarily, open a file, press ESC and type :colorscheme morning:

:colorscheme morning

The change is temporary; closing Vim resets it.

To make a scheme permanent, edit .vimrc and add, for example, a night scheme:

color evening
set background=dark

Reopen the file to see the new appearance:

Choose Color Scheme by Language

Vim supports syntax for many languages (PHP, Perl, Python, etc.). To view a file with a different language’s highlighting, use :set syntax=perl (or another language):

:set syntax=perl

Custom Color Scheme

Vim defines nine highlight groups (Identifier, Statement, Comment, Type, PreProc, Constant, Special, Underlined, Error). You can change their colors with :hi commands. For example, to make statements red:

:hi Statement ctermfg=red

Similarly, you can adjust colors for comments, constants, types, etc., to create a personalized color scheme.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Editor Configurationterminalsyntax highlightingcolor scheme
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.