Question

I would like to show ‘␣’ instead of non-breaking spaces since they are invisible by default, and added the following lines to my vimrc:

syntax match nonbreaking "\%xa0" conceal cchar=␣
set conceallevel=1
highlight nonbreaking ctermbg=NONE guibg=NONE

While this works, it also adds a background colour to all occurrences of non-breaking spaces – even with the {cterm,gui}bg=NONE line:

enter image description here

Is there a way to “hide” U+00ad behind ‘␣’ without affecting how it's highlighted at all?

Was it helpful?

Solution

well, it's not a direct answer to your question about background of concealed characters, though here is a solution to your problem:

to show non-breakable spaces as you should better use the listchars setting:

:set listchars=nbsp:␣

and here's my complete listchars setting, in case you're interested:

:set listchars=eol:¶,trail:~,extends:⫸,precedes:⫷,tab:▸ ,nbsp:␣

and this will not affect the colours.

More about it :he listchars

HTH

OTHER TIPS

I'd also recommend against using the conceal feature for this, as it can interfere with the existing syntax highlighting; the use of 'listchars' as suggested by @zmo is preferable (but :set list has side effects, e.g. with wrapping, too).

For completeness, you can influence the visual appearance of the concealed characters via the Conceal highlight group.

:hi clear Conceal

clears the existing highlighting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top