1. Home
  2. Linux
  3. Vim highlights texts in Red? Here’s how you can stop that!

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

Here’s a question from Mr. Rajan, one of the regular reader 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 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 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 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 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

Lookout 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 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
Updated on November 10, 2017

Was this article helpful?

Related Articles

Add A Comment