1

Say that I have pattern aaaaapple in my text file, and say that I configured vim so that it conceals a\+.

What will happen is that, if conceallevel=1, then aaaaapple will become _pple. Note that aaaaa is replaced by a single space _ (I'm writing spaces as _ due to technical difficulties). This causes the line to jiggle/dance every time I hover on the concealed word, due to the single space _ expanding into 5 characters aaaaa.

What I want is to conceal aaaaapple such that it becomes _____pple instead of _pple. This way, when I move to the line where this conceal happened, the text won't jiggle/dance by expanding/shrinking. I.e. it looks like _____pple before hovering on it, and aaaaapple after hovering on it. No jiggling!

Any idea how to do this conceal such that each concealed character is replaced by a space (and not replacing all concealed characters by a single space)?

3

Instead of matching all duplicate "a"s in a single match, try concealing each extra "a" in its own, concealed group:

syn match HideAa "a\zea" conceal

Because this conceals only a single "a" with its own syntax group conceal, it will effectively apply a concealing space to each "a".

  • Thanks. It works! An extra variation: is it possible to make this conceal apply only when aaaaapple is prefixed by, say, xx? E.g. only xxaaaaapple` becomes _______pple, but aaaaapple (without xx) to not become _____pple? – caveman Nov 21 at 23:25
  • You can do it with 2 commands together: syn match HideAa "a\zea" conceal contained and syn match HideXxAa "xxa\+" contains=HideAa – nickspoon Nov 21 at 23:35
  • Something to note: this will "consume" the first a, so that no other match can overlap with it – D. Ben Knoble Nov 22 at 1:59
1

See :h concealcursor. It controls which modes will be activated for conceal. In this case you want to disable it for normal mode. I recommend trying setl concealcursor=vic

  • I'm not sure the OP wants to disable conceal in normal mode—that's not my read of the question – D. Ben Knoble Nov 22 at 1:58

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.