11

在谷歌上搜索 vsvim 前瞻或后视以及在wiki上搜索后,我似乎无法弄清楚它是否支持前瞻或后视(正面或负面)以及如何使用它们。

我尝试了一些不同的语法,就像\ze \@= (?<=let \w\+)( \(?<=let \w\+\)(我在 vim答案中看到的那样,但它们似乎都没有在 vs vim 中用于匹配(也不是替换)

你如何在 VsVim 中进行环视?

4

2 回答 2

3

对于任何新人,我将在此处复制此链接的内容以备将来使用:

http://ssiaf.blogspot.ru/2009/07/negative-lookbehind-in-vim.html

/\(Start\)\@<!Date

这将匹配“EndDate”和“YesterdaysDate”中的“Date”,但不匹配“StartDate”

/Start\(Date\)\@!

将匹配“开始”中的“开始”,但不匹配“开始日期”

/Start\(Date\)\@=

将匹配 'StartDate' 中的 'Start' 但不匹配 'Starting

/\(Start\)\@<=Date

将匹配 'StartDate' 中的 'Date' 但不匹配 'EndDate' 和 'YesterdaysDate'

于 2016-10-14T00:08:31.647 回答
1

I want to expand on the excellent answer from @briansrls. I was looking for a more robust solution that could handle multi-word phrases, wildcards (for potential gaps between phrases) and alternatives (i.e., patterns):

Without wildcards:

  Positive Lookahead:  \(find this\)\(followed by this\|or that\)\@=
  Negative Lookahead:  \(find this\)\(not followed by this\|or that\)\@!
  Positive Lookbehind: \(preceded by this\|or that\)\@<=\(find this\)
  Negative Lookbehind: \(not preceded by this\|or that\)\@<!\(find this\)

With wildcards:

  Positive lookahead:  \(find this\)\(.*\(eventually followed by this\|or that\)\)\@=
  Negative lookahead:  \(find this\)\(.*\(not eventually followed by this:\|or that\)\)\@!
  Positive lookbehind: \(\(eventually preceded by this\|or that\).*\)\@<=\(find this\) 
  Negative lookbehind: \(\(not eventually preceded by this\|or that\).*\)\@<!\(find this\)

Note: For the wildcard versions, the extra parentheses are required so that the wildcard is excluded from the alternatives group, but is included in the lookaround group. This prevents duplicating the wildcards for every alternative. One could also use \zs & \ze to avoid the extra parentheses, but I find this method slightly more intuitive.

For more information:

Update: It appears that \zs & \ze are not yet implemented in VsVim as of this time.

于 2018-08-06T20:34:40.553 回答