Using a regex to mark a particular form as accepted spelling?

19 views
Skip to first unread message

Tim Chase

unread,
Aug 27, 2025, 9:29:47 PM (8 days ago) Aug 27
to Vim Users
Taking some notes, I have a lot of page-references of the form "p12",
"p35-36", etc. With 'spell' set, it highlights them as misspelled
words. However, I can formulate a regex that would identify these:

/\<p\d\+\%(-\d\+\)\=\>/

Is there a way to convey this information to vim so that they get
ignored for spellcheck purposes?

I know there's some highlight-group aspect that might be usable,

contains=@NoSpell

as detailed at `:help spell-syntax`, so I think I have the relevant
pieces, but am just failing to put them together in the right way
(writing syntax files is not my forte)

What do I need to do to assemble these so spell-checking ignores my
page-number ranges?

Thanks,

-tim
--





Maxim Kim

unread,
Aug 28, 2025, 7:07:00 AM (8 days ago) Aug 28
to vim_use
Try
   
   syntax match MyPages /\<p\d\+\%(-\d\+\)\=\>/ contains=@NoSpell

This would work for an existing buffer, to (auto)apply it, let's assume you're in filetype=text

augroup NoSpellPages
    au!
    au Filetype text syntax match MyPages /\<p\d\+\%(-\d\+\)\=\>/ contains=@NoSpell
augroup END



Screenshot_20250828_210140.png

Tim Chase

unread,
Aug 28, 2025, 7:59:10 AM (8 days ago) Aug 28
to vim...@googlegroups.com
On 2025-08-28 04:06, Maxim Kim wrote:
> syntax match MyPages /\<p\d\+\%(-\d\+\)\=\>/ contains=@NoSpell

My spell-highlight is now much more useful because it's no longer so
visually cluttered. Thanks so much!

-tim
--





Reply all
Reply to author
Forward
0 new messages