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?

New contributor
Ali Hardan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • I believe it’s a unicode char, hence the display, but you could possibly do it with conceal – D. Ben Knoble Nov 10 at 6:30
  • Use a font, that contains a glyph for that character is no option? – Christian Brabandt yesterday
  • @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. – Ali Hardan yesterday
  • 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 – Christian Brabandt 22 hours ago
  • @ChristianBrabandt, You can post it as an answer. – Ali Hardan 22 hours ago
up vote 1 down vote accepted

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 :)

  • Who want to make ZWNJ character hidden in insert mode: :set concealcursor+=i – Ali Hardan 21 hours ago

Your Answer

Ali Hardan is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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