Saturday, March 5, 2011

Re: limit syntax match to not match strings starting with dashes

> Hello vimmers,

Hello!

> I'm using the PS1.vim syntax file while writing Powershell scripts.
>
> It has a line like this:
> syn match ps1Cmdlet /\w\+-\w\+/
>
> which should (and does) match command names like Write-Debug, Get-Date, etc.
>
> However, it also incorrectly matches command line arguments like
> mysqldump --single-transaction
>
> where "single-transaction" is highlighted with the ps1Cmdlet colors.
>
> How can I change this so that it matches the verb-noun syntax that Powershell uses
> but doesn't match the dashed arguments?

Hmmm. So many choices.

One possibility would be checking there is whitespace or beginning of
line before the match starts:

:syn match ps1Cmdlet /\(^\|\s\)\zs\w\+-\w\+/

Another possibility would be

:set iskeyword+=-

to include the - as a keyword character, which might be appropriate if
keywords often include that, and it isn't really used as an operator.
Then you could delimit the word for the syntax highlighting, though
you'd still have to do something fancy to ensure that - doesn't count as
the start of the word:

:syn match ps1Cmdlet /\<\h\k*/

I'm sure there are more possibilities, but maybe one of them will do?

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment