2

Is there a (*SKIP) equivalent in the Vim regex engine? (without using :perldo etc)

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Vimminator
  • 35
  • 4
  • Please add more details on your issue, perhaps, you can do without the (*SKIP) verb. Still, [you can use PCRE in Vim](http://stackoverflow.com/a/33081758/3832970). – Wiktor Stribiżew Dec 03 '15 at 08:21
  • As said already, I don't want to use any other regex engines. I just want to know whether there is a (*SKIP) equivalent in vim. (It is not about a particular issue but let's take for example the "famous" regex pattern 'not this(*SKIP)(?!)|but this' – Vimminator Dec 03 '15 at 08:37
  • try reading `:help pattern` – mMontu Dec 03 '15 at 11:03

1 Answers1

3

No, according to how do skip or f work on regex, it's only implemented in PCRE.

The answer explains that this can be implemented in other ways, especially since Vim has variable-length lookbehind. So /not this(*SKIP)(?!)|but this/ could be formulated in Vim as this:

/^\%(.*not this\)\@!.*\zsbut this/

I don't have a general recipe to translate (*SKIP) into Vim's regexp dialect, but it should be possible to express any such expression in Vim, too (but the resulting regexp may not be as tidy and have repetitive information).

Community
  • 1
  • 1
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • `(*SKIP)` is [implemented in perl too](http://perldoc.perl.org/perlre.html#(*SKIP)-(*SKIP%3aNAME)) – Mariano Dec 03 '15 at 13:28
  • I also think 'No' is the correct answer. I haven't accepted your answer yet because your example `/^\%(.*not this\)\@!.*\zsbut this/` doesn't seem to work. Could you please check? – Vimminator Dec 03 '15 at 17:17
  • @Vimminator: The pattern matches `but this` in lines that do not contain `not this` (i.e. not before and not after). What else it is supposed to match? – Ingo Karkat Dec 03 '15 at 17:23
  • Understand, you took my "pattern" example (almost) literally. Here is a "real" example (taken from the great rexegg site): `{[^}]*}(*SKIP)(?!)|\b\w+\b`. This selects all words not surrounded by curly braces (assuming there are no nested curly braces). – Vimminator Dec 03 '15 at 17:53
  • I have accepted the answer although the part `/not this(*SKIP)(?!)|but this/` could be formulated in Vim as this: `/^\%(.*not this\)\@!.*\zsbut this/` is not really correct. The answer would have been better if Ingo removed that part :-) – Vimminator Dec 11 '15 at 08:01
  • @Vimminator: Thanks, I appreciate that! I've added a caveat that the example isn't a general solution; unfortunately, I cannot give such. – Ingo Karkat Dec 11 '15 at 08:47