Skip to content
Home » How to Change the Color of Comments in the vi Application?

How to Change the Color of Comments in the vi Application?

By default, if you open the vi application on Linux (especially using PuTTY), the color for comments is blue. However, sometimes this makes it very difficult for me to read the comments, especially if the background color of the terminal is black.

 

Problem

How to change the color of comments in the vi application?

 

Solution

Below is an image of a /etc/crontab file opened using Putty:

Comment color in the vi application

 

For me, it’s very difficult to read the comments in the Linux file if they’re blue like in the image above. So, if you want to change the color of comments in the vi application, for example, if you want to change the color of comments to yellow, then open the .vimrc file by:

vi ~/.vimrc

 

Type the script below into the file:

highlight Comment ctermfg=yellow

 

After that, open the file using the vi application, and the comments on the file should change to yellow as in the image below:

change the color of comments in the vi
Comment color after configuration in the vi application

 

You can see that the comment color is changed to yellow after you configure the .vimrc file.

Info
Please note that the steps above only change per user. If you want all users to change the comment color to yellow then place the above command in the /etc/vim/vimrc.local file.

 

Note

Currently, the vi application can support up to 256 colors that can be used in the vi application. So if you want to use more colors supported by the vi application, in the .vimrc file type the script below:

set t_Co=256

 

Then you can choose the colors on this page, for example, you want to use purple for comments, then enter the script below in the .vimrc file:

set t_Co=256
highlight Comment ctermfg=93

 

Then the comments in the vi/vim application should be purple as in the image below:

change the color of comments in the vi
Change the color of comments in the vi

 

References

spinspire.com
linode.com

image_pdfimage_print
Visited 17 times, 1 visit(s) today
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *