Vim highlights texts in Red? Here’s how you can stop that!

Updated on October 20, 2021

Here’s a question from Mr. Rajan, one of the regular readers at Techglimpse. His issue is why vim highlights texts in red?

I’m seeing a strange behavior of vim editor that highlights all texts in red color and it happens only when /etc/sysconfig/named file is opened. Here’s the screenshot of the issue. I’m able to edit the file, save and do all vim operations without any issue, but still the red texts is really annoying. How to get rid of this?

Why vim highlights text in Red?

Hi Rajan, I tried to replicate the issue in the Techglimpse lab, but couldn’t reproduce the same. However, there’s a reason for vim highlighting texts in red color. Generally, vim has plugins to understand the syntax of programming languages and certain configuration files. For example, vim can understand comments and highlight those texts in blue color and variables in green, etc…Similarly, errors are generally highlighted in red color and it looks like vim does not know how the syntax should be handled for /etc/sysconfig/named.

However, highlighting of error messages is done with the help of Error and ErrorMsg highlight groups. So try to highlight groups as shown below.

Step 1: Open the file and type the below in last-line mode (ESC & semi-colon).

:hi Error

Vim will display the values set for Error the highlight group as shown below:

Error xxx term=reverse cterm=bold ctermfg=7 ctermbg=1 guifg=White
 guibg=Red

(or)

:verbose hi Error
Error xxx term=reverse cterm=bold ctermfg=7 ctermbg=1 guifg=White
 guibg=Red
 Last set from /usr/share/vim/vim74/syntax/syncolor.vim

Look out for guifg & guibg, which stands for GUI foreground and GUI background respectively.

Step 2: To stop vim using Error groups, type:

:hi Error NONE

Still, seeing red texts? Then you may have to disable ErrorMsg it as well.

:hi ErrorMsg NONE

Hope it helps.

Note: Executing :hi Error NONE inside the vim editor is only a temporary solution. If you ever want to disable Error highlight for every file type, then you need to set the same in ~/.vimrc as shown below:

au ColorScheme * hi Error NONE
au ColorScheme * hi ErrorMsg NONE
au GuiEnter * hi Error NONE
au GuiEnter * hi ErrorMsg NONE

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. Thank You 🙂 I had that ugly Highlight for years, and never thought of removing it.. now I just did .. it was not even pointing to an error ! Thank you

Leave a Comment