Concealing a character in Vim without affecting how it's highlighted

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:

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

Answers


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


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.


Need Your Help

What does it mean when you say C# is component oriented language?

c#

I learned Java while ago. I just got bored of Java and returned to C++ after a while. I thought that C# was similar to Java. My assumption about the similarities between C# and Java was not correct...

How to get text position using Tesseract OCR API in C++?

c++ opencv image-processing ocr tesseract

I am doing character recognition in ID cards in opencv-2.x using C++. I tried Tesseract OCR, but it didn't give me better results than my own neural network training and all. Although, I am still