Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A Syntax match any 2 spaces at end of line

You could explicitly match the other whitespace, too, to see if that gets around an existing rule.[1] Here are two ways to do that:[2] Match the other whitespace in another rule You could use a \...

posted 7mo ago by Michael‭  ·  edited 7mo ago by Michael‭

Answer
#3: Post edited by user avatar Michael‭ · 2024-05-24T15:20:26Z (7 months ago)
Mention marking extraneous whitespace.
  • It's not ideal, but you could explicitly match the other whitespace, too, to see if that gets around a default rule.[^default][^magic] Here are two ways to do that:
  • ### Match the other whitespace in another rule
  • You could use [a `\@=` lookahead][lookahead] to match all the whitespace before your special rule. This might cajole your original rule into matching, since it's back to the last two chars.
  • ```vim
  • syntax match Normal /\v\s(\s{2}$)\@=/
  • syntax match Normal /\v\s{2}$/ conceal cchar=⏎
  • ```
  • ### Match everything, but start capture at the last two space chars
  • Vim lets you start the capture late[^ze] with [a `\zs` capture start][match-start] marker. It's possible there are weird interactions between that and `conceal`, but it might work.
  • ```vim
  • syntax match Normal /\v\s*\zs\s{2}$/ conceal cchar=⏎
  • ```
  • [^default]: As it turns out, there was [a default rule in the Markdown language syntax][markdown] that matched *all* the whitespace at EOL. If there was whitespace that wasn't exactly two characters, the default rule would consume the whole string without giving other rules a chance.
  • [^magic]: Please excuse my `\v` modifier. It's just much easier for me to interpret Vim regex with it.
  • [^ze]: Or end the capture early with `\ze`
  • [lookahead]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\@=
  • [match-start]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\zs
  • [markdown]: https://software.codidact.com/comments/thread/9562#comment-24073
  • You could explicitly match the other whitespace, too, to see if that gets around an existing rule.[^default] Here are two ways to do that:[^magic]
  • ### Match the other whitespace in another rule
  • You could use [a `\@=` lookahead][lookahead] to match all the whitespace before your special rule. This might cajole your original rule into matching, since the remainder is back to the last two chars.
  • ```vim
  • syntax match Normal /\v\s(\s{2}$)\@=/
  • syntax match Normal /\v\s{2}$/ conceal cchar=⏎
  • ```
  • One small advantage of this approach is you could set the extraneous whitespace to a different group and highlight it separately to mark it as unnecessary.
  • ### Match everything, but start capture at the last two space chars
  • Vim lets you start the capture late[^ze] with [a `\zs` capture start][match-start] marker. It's possible there are weird interactions between that and `conceal`, but barring that it should work.
  • ```vim
  • syntax match Normal /\v\s*\zs\s{2}$/ conceal cchar=⏎
  • ```
  • [^default]: [As it turns out][markdown-thread], there was [a rule in the Markdown language syntax][markdown] that matched *all* the whitespace at EOL. If there was whitespace that wasn't exactly two characters, the default rule would consume the whole string without giving other rules a chance to match later substrings of consumed characters.
  • [^magic]: Please excuse [my `\v` modifiers][magic]. It's much easier for me to comprehend Vim regex with it.
  • [^ze]: Or end the capture early with [`\ze`][match-end]
  • [lookahead]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\@=
  • [match-start]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\zs
  • [match-end]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\ze
  • [markdown-thread]: https://software.codidact.com/comments/thread/9562#comment-24073
  • [markdown]: https://github.com/vim/vim/blob/35dfe58a540e2fb0eff953630f8e4fcbf4bc26ca/runtime/syntax/markdown.vim#L95
  • [magic]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/magic
#2: Post edited by user avatar Michael‭ · 2024-05-23T21:15:48Z (7 months ago)
Link the discovery in the comment thread.
  • These are horrible ways to fix your problem, but you could try to explicitly match the other whitespace, too. Here are two possibilities:
  • ### Match the other whitespace in another rule
  • Here using [a `\@=` lookahead][lookahead]. The idea here is that you might be able to cajole your original rule into matching since it's back to the last two chars.
  • ```vim
  • syntax match Normal /\v\s(\s{2}$)\@=/
  • syntax match Normal /\v\s{2}$/ conceal cchar=⏎
  • ```
  • ### Match everything, but start capture at the last two space chars
  • I don't know what interactions Vim might have between `conceal` and [a `\zs` capture start][match-start]. But it might work.
  • ```vim
  • syntax match Normal /\v\s*\zs\s{2}$/ conceal cchar=⏎
  • ```
  • [lookahead]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\@=
  • [match-start]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\zs
  • It's not ideal, but you could explicitly match the other whitespace, too, to see if that gets around a default rule.[^default][^magic] Here are two ways to do that:
  • ### Match the other whitespace in another rule
  • You could use [a `\@=` lookahead][lookahead] to match all the whitespace before your special rule. This might cajole your original rule into matching, since it's back to the last two chars.
  • ```vim
  • syntax match Normal /\v\s(\s{2}$)\@=/
  • syntax match Normal /\v\s{2}$/ conceal cchar=⏎
  • ```
  • ### Match everything, but start capture at the last two space chars
  • Vim lets you start the capture late[^ze] with [a `\zs` capture start][match-start] marker. It's possible there are weird interactions between that and `conceal`, but it might work.
  • ```vim
  • syntax match Normal /\v\s*\zs\s{2}$/ conceal cchar=⏎
  • ```
  • [^default]: As it turns out, there was [a default rule in the Markdown language syntax][markdown] that matched *all* the whitespace at EOL. If there was whitespace that wasn't exactly two characters, the default rule would consume the whole string without giving other rules a chance.
  • [^magic]: Please excuse my `\v` modifier. It's just much easier for me to interpret Vim regex with it.
  • [^ze]: Or end the capture early with `\ze`
  • [lookahead]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\@=
  • [match-start]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\zs
  • [markdown]: https://software.codidact.com/comments/thread/9562#comment-24073
#1: Initial revision by user avatar Michael‭ · 2024-05-22T20:18:30Z (7 months ago)
These are horrible ways to fix your problem, but you could try to explicitly match the other whitespace, too. Here are two possibilities:

### Match the other whitespace in another rule
Here using [a `\@=` lookahead][lookahead]. The idea here is that you might be able to cajole your original rule into matching since it's back to the last two chars.
```vim
syntax match Normal /\v\s(\s{2}$)\@=/
syntax match Normal /\v\s{2}$/ conceal cchar=⏎
```

### Match everything, but start capture at the last two space chars
I don't know what interactions Vim might have between `conceal` and [a `\zs` capture start][match-start]. But it might work.
```vim
syntax match Normal /\v\s*\zs\s{2}$/ conceal cchar=⏎
```

[lookahead]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\@=
[match-start]: https://vimdoc.sourceforge.net/htmldoc/pattern.html#/\zs