How to add Colors to VIM (syntax highlighting)

Background about ~/vimrc file

    In order to apply color schemes to VIM you would need to update the .vimrc file which is a configuration file that is read when Vim starts up. Using this file you can customize Vim's behavior and settings to suit your preferences. The file is a plain text file that you will find under the home directory.

    % vim ~/.vimrc
    Note: If this file does not exist, this file will be created as you make use of the command vim ~/.vimrc i.e. Vim will create the file if it does not already exist.

Steps: Setting Custom Color Schema (Syntax Highlighting)

  • Open Terminal/Bash Console.
  • Type the below command to open the .vimrc file.
    vim ~/.vimrc
  • Now add the following line at the end of the file (if the file is blank at the beginning)
    syntax on
    colorscheme <color-scheme-name>

    Some of the colorschemes available by default to choose from:

    desert: A low-contrast colorscheme with warm, earthy tones.
    molokai: A high-contrast colorscheme with a dark background and bright colors.
    gruvbox: A retro-inspired colorscheme with muted colors and a warm background.
    solarized: A popular colorscheme with a light and dark variant, designed to reduce eye strain.
    monokai: A high-contrast colorscheme with bright, saturated colors.
  • Make sure to save and quit the file using :wq
  • Now when you will open VIM again you will see the color scheme has been applied.
Adding Color Scheme for Syntax Highlighting for VIM

As you would see in the below example, we created a file and as we type the code and syntax get highlighted in colors based on the keyword and string.

Example of Color coding with VIM

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap