In Vim can you stop the color change of white spac

2019-03-12 16:39发布

问题:

In this Vim screenshot you can see that when moving the cursor over a line it changes the normal color of the whitespace characters (shown on the left) from grey to black. Can I stop this and leave them showing grey always, regardless of cursor position?

I've tried setting these in the colour scheme but no luck:

hi SpecialKey  guibg=bg  guifg=#CCCCCC gui=none
hi NonText     guibg=bg  guifg=#CCCCCC gui=none

回答1:

You can use :match to highlight the tabs.

:match NonText '^\s\+'

That seems to override the cursor line. It would be better of course to use matchadd() but it seems to be overriden by the cursor line. There might be a way to make it work



回答2:

Following lines in .vimrc fixed the problem for me.

au VimEnter * call matchadd('SpecialKey', '^\s\+', -1)
au VimEnter * call matchadd('SpecialKey', '\s\+$', -1)

It overrides other styles application for tabs and trailing spaces inside a cursor line.



回答3:

Yes you can. From :help listchars (at the end):

The "NonText" highlighting will be used for "eol", "extends" and "precedes". "SpecialKey" for "nbsp", "tab" and "trail".

With this knowledge you can modify your color scheme accordingly or add a call to highlight in your vimrc.



回答4:

I believe you have 'cursorline' set. The CursorLine highlight group defines the highlights for the same. Either you set nocursorline, (which can speed line movements) or change the CursorLine highlight groups fg colors.



标签: vim cursor line