2

When I insert a ZWNJ character into text, vim displays <200c> instead of it.

Is it possible to make vim to behave normally with this character, like GUI editors? Or is it possible to hide (and not remove) this character in vim's display?

6
  • I believe it’s a unicode char, hence the display, but you could possibly do it with conceal
    – D. Ben Knoble
    Nov 10, 2018 at 6:30
  • Use a font, that contains a glyph for that character is no option? Nov 12, 2018 at 10:17
  • @ChristianBrabandt, The ZWNJ character is a non-printing character. See here. So, I think not exists any font contains glyph for it. and if it exists, it not the fix, because I don't want to be appear a new character for it.
    – alihardan
    Nov 12, 2018 at 22:35
  • Then you can try to conceal the character. Try the following: :call matchadd('Conceal', '‌<200c>', 10, -1, {'conceal':''}) :set conceallevel=2 concealcursor=nv (the <200c> needs to be the ZWNJ character copied literally Nov 13, 2018 at 7:11
  • @ChristianBrabandt, You can post it as an answer.
    – alihardan
    Nov 13, 2018 at 7:16

1 Answer 1

2

What you can do, is conceal characters that you want to be displayed differently. Concealing means to change how a character (or a pattern) looks like in your current window.

For your specific case, you can do this:

:call matchadd('Conceal', '‌\%u200c', 10, -1, {'conceal':''})
:set conceallevel=2 concealcursor=nv

The first statement sets up a conceal rule for your character ZWNJ and uses the regular expression atom /\%u (by matching a character against its Unicode codepoint value.

The second statement sets up the actual conceal setting for your window. So it will make sure that concealed characters will be hidden in normal and visual mode (even if the cursor is on that line). For more information have a look at :help 'concealcursor' and :help 'conceallevel'.

Note however, this is a mere visual feature and it won't change the actual text. In fact, even the text wrapping will occur only on the physical text representation which might let the text wrapping look a bit strange. However this has been classified as no bug and probably won't change in the future.

Note also, this is a window specific setting. So it would have to be done in each window, where you like to change the visual representation. For specific filetypes, you could even convert this to a specific filetype plugin. But that is the topic of another question/answer :)

1
  • Who want to make ZWNJ character hidden in insert mode: :set concealcursor+=i
    – alihardan
    Nov 13, 2018 at 7:29

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.