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.

Comments on Syntax match any 2 spaces at end of line

Post

Syntax match any 2 spaces at end of line

+4
−0

I'm using the following syntax match to conceal 2 spaces at the end of a line with a special character.

syntax match Normal '\s\{2}$' conceal cchar=⏎

A line with two spaces at the end of it would display like this:

some line with two trailing spaces⏎

However, if there are more than two spaces I don't get the special character. I would expect that this would still match on the last two spaces. For example:

a line with 4 trailing spaces  ⏎

Instead, it shows all 4 spaces with no special character.

If I do a normal search for /\s\{2}$, it will find 2 spaces at the end of the line, even if there are additional preceding spaces. Whereas the syntax match still matches if other characters proceed 2 trailing spaces, but not if the proceeding characters are spaces.

Why doesn't my syntax match work if there are proceeding spaces? How can I match 2 trailing spaces on a line, even if there are additional spaces before it?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Can you reproduce this with no other syntax rules in the buffer (you can clear the current buffer wit... (5 comments)
Can you reproduce this with no other syntax rules in the buffer (you can clear the current buffer wit...
r~~‭ wrote 6 months ago · edited 6 months ago

Can you reproduce this with no other syntax rules in the buffer (you can clear the current buffer with :syntax clear)? I'm unable to but I'm using Neovim.

If not, can you use that to find the rule that conflicts?

rcmosher‭ wrote 6 months ago

It works after doing that. I wasn't expecting that as I'd previously opened my file with vim --clean. I'd assume it's a standard markdown syntax file that's conflicting. Time to start looking.

Michael‭ wrote 6 months ago

vim /usr/share/vim/vim90/syntax/markdown.vim? I poked around at the skipwhite entries, but none them jumped out as suspicious.

rcmosher‭ wrote 6 months ago

Found it: syn match markdownLineBreak " \{2,\}$". I found it using a mapping I made for synIDattr() to get the syntax ID. Looks like syntax clear markdownLineBreak gets what I want. Funny that there's a standard match that is going unused.

Michael‭ wrote 6 months ago

Nice. Maybe write up a self-answer, so it's not buried in a comment thread?