简体   繁体   English

Vim错误E488:用gn标志替换时的尾随字符

[英]Vim Error E488: Trailing characters on substitution with gn flags

I am trying to count occurrences of some regex in vim with following command: 我试图用以下命令计算vim中某些正则表达式的出现次数:

:%s/class=//gn

or even: 甚至:

:%s/class=/&/gn

But I keep getting E488: Trailing characters . 但我一直得到E488: Trailing characters This is even suggested in official documentation http://vimdoc.sourceforge.net/htmldoc/tips.html#count-items 甚至在官方文档中也提到了这一点http://vimdoc.sourceforge.net/htmldoc/tips.html#count-items

Can anyone help/explain this ? 有人可以帮忙/解释一下吗? The only way I have found out to be working is :%s/class=/&/g but this is in my opinion a little overkill since it actually substitutes regex with the same characters tat have been found instead of just counting the occurrences. 我发现工作的唯一方法是:%s/class=/&/g但是在我看来这有点矫枉过正,因为它实际上用相同的字符代替正则表达式而不是仅计算出现次数。

I am using VIM 6.3 我正在使用VIM 6.3

After some searching I found this in :help improvements-7 : 经过一番搜索,我发现了这个:help improvements-7

To count items (pattern matches) without changing the buffer the 'n' flag has been added to :substitute.

Thus you have to upgrade to 7.0 at least. 因此,您必须至少升级到7.0。 :-) :-)

The n flag for the :s command has been implemented with Vim 7. Sou you need to upgrade your Vim version. 使用Vim 7实现了:s命令的n标志。您需要升级Vim版本。 Considering that Vim 6.2 (I think, it was released on June 1st, 2003) was released more than 10 years ago, it's nevertheless a good idea to upgrade, since then several new features and bug fixes have been included. 考虑到Vim 6.2(我认为,它于2003年6月1日发布)在10多年前发布,升级是一个好主意,因为这时已经包含了几个新功能和错误修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM