Re: Wildcards in Spell-check?

72 views
Skip to first unread message

Ben Fritz

unread,
Nov 1, 2012, 10:34:23 AM11/1/12
to vim...@googlegroups.com
On Wednesday, October 31, 2012 3:49:22 PM UTC-5, Ian Donegan wrote:
> I am trying to find a way to use pattern recognition in spell-check. At the moment, I am not even sure if that is possible, but it seems like it should be. If I want to have a url in a file with ":set spell" I have to either mark the link as correct or deal with the red hilighting. Is there any way to white-list everything that starts with "http://"? Thanks in advance.

Well, spelling integrates with syntax highlight. You could define a simple syntax to recognize the URLs and disallow spelling in that syntax region.

Ian Donegan

unread,
Nov 1, 2012, 10:22:23 PM11/1/12
to vim...@googlegroups.com

Great. Thanks for the response. I am relativity new to Vim though, so I have no idea how I would go about setting up syntax hilighting rules. The closest thing that I could find in the help file was something about "contains=@NoSpell" but I do not really understand it. How would I go about setting it up, or at least, where could I read more about it?

Ben Fritz

unread,
Nov 2, 2012, 11:00:28 AM11/2/12
to vim...@googlegroups.com
:help syntax
:help :syn-match

If you are just editing a plaintext file with no existing syntax highlighting, it is very easy. Assuming you have "syntax on" in your .vimrc somewhere, just do something like this:

:syntax match NoSpellURL 'http://\S*' contains=@NoSpell

You can type this directly, put it in a mapping or command, or put this in a file with pretty much any name you want, in ~/.vim/syntax, and set the syntax to the chosen name to activate it. E.g. if you name the file ~/.vim/txtspell.vim you can do :set syntax=txtspell to apply the rule.

It gets somewhat more complicated if you have an existing syntax you want to enhance with this rule but is still quite possible. The "after directory" is useful for this, i.e. ~/.vim/after/syntax.

Ian Donegan

unread,
Nov 2, 2012, 1:57:02 PM11/2/12
to vim...@googlegroups.com

Well, I thank you, Ben Fritz. I stuck that line in my .vimrc file and it fixed my problem for the most part. I still do not understand all of the syntax behind it yet but I should be able to figure the rest out with the help of the manual. It has been a pleasure learning from you.

Ben Fritz

unread,
Nov 2, 2012, 3:59:45 PM11/2/12
to vim...@googlegroups.com
On Friday, November 2, 2012 12:57:02 PM UTC-5, Ian Donegan wrote:
> >
> > :syntax match NoSpellURL 'http://\S*' contains=@NoSpell
> >
>
> Well, I thank you, Ben Fritz. I stuck that line in my .vimrc file and it fixed my problem for the most part. I still do not understand all of the syntax behind it yet but I should be able to figure the rest out with the help of the manual. It has been a pleasure learning from you.

If you never apply any other syntax highlighting, I suppose adding it to your .vimrc will work.

But more likely eventually you'll edit something syntax highlighted. I suggest wrapping it in a command or syntax plugin of your own.

See :help new-filetype for detecting when to apply the plugin. See :help usr_44.txt for setting up the syntax plugin itself.

Ian Donegan

unread,
Nov 2, 2012, 4:28:12 PM11/2/12
to vim...@googlegroups.com

That is probably what I will end up doing. I discovered that if I just have it in my .vimrc file, it will not take effect when I restore a session, or like you said, when I edit file types that have other syntax highlighting.

Reply all
Reply to author
Forward
0 new messages