2

I have some code in my ~/.vimrc to highlight trailing whitespace.

" Highlight trailing whitespace
hi TrailingWhitespace ctermbg=red guibg=red
matchadd("TrailingWhitespace", '\v\s+$')

I only want to see trailing whitespace when I am in normal mode, not when I am in insert mode.

highlighting occurs when in insert mode

How can I accomplish that highlighting only occurs in normal mode?

1 Answer 1

0

The Vim Better Whitespace Plugin does exactly what I want:

This plugin causes all trailing whitespace characters (see Supported Whitespace Characters below) to be highlighted. Whitespace for the current line will not be highlighted while in insert mode. It is possible to disable current line highlighting while in other modes as well (see options below).

Install the plugin (or copy the content of better-whitespace.vim) and add this line to your .vimrc:

hi ExtraWhitespace ctermbg=red guibg=red

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.