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.
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:
- 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 Adding Color Scheme for Syntax Highlighting for VIM](https://code2care.org/q/add-colors-to-vim-syntax-highlighting/images/Adding Color Scheme for Syntax Highlighting for VIM.png)
As you would see in the below example, we created a file Hello.java and as we type the code and syntax get highlighted in colors based on the keyword and string.
![Example of Color coding with VIM Example of Color coding with VIM](https://code2care.org/q/add-colors-to-vim-syntax-highlighting/images/Example of Color coding with VIM.png)
Facing issues? Have Questions? Post them here! I am happy to answer!
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: rakesh@code2care.org
- How to add Colors to VIM (syntax highlighting)
- How to perform Find and Replace using vim Editor
- How to update VIM version on a Mac
- How to Select All Text in Vim/Vi editor
- Guide: Install Vim on Mac
- The Vim (vi) Mac Configuration File Details
- Fix :wq! Vi Error - E32: No file name (when write and quit)
- How to Copy all text to Clipboard in Vim
- How to Uninstall Vim on Mac?
- Install GCC on M1/M2 ARM Based Mac - MacOS
- How to Measure Execution Time in Jupyter Notebook Cell - Python
- [fix] App store not working on Mac, Blank Black or White Screen - MacOS
- How to create a SharePoint list from an existing list with same columns, views, formatting, data - SharePoint
- Fix: error: could not lock config file /etc/gitconfig: Permission denied - Git
- [fix] SharePoint: We only support embedding content from secure websites - SharePoint
- How to change Android Button Color using xml attribute and programatically using java - Android
- How to redirect SharePoint Site Collection to different URL - SharePoint