1

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?

  • I believe it’s a unicode char, hence the display, but you could possibly do it with conceal – D. Ben Knoble Nov 10 '18 at 6:30
  • Use a font, that contains a glyph for that character is no option? – Christian Brabandt Nov 12 '18 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. – Ali Hardan Nov 12 '18 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 – Christian Brabandt Nov 13 '18 at 7:11
  • @ChristianBrabandt, You can post it as an answer. – Ali Hardan Nov 13 '18 at 7:16
1

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 Nov 13 '18 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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