简体   繁体   中英

Vim Error E488: Trailing characters on substitution with gn flags

I am trying to count occurrences of some regex in vim with following command:

:%s/class=//gn

or even:

:%s/class=/&/gn

But I keep getting E488: Trailing characters . This is even suggested in official documentation 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.

I am using VIM 6.3

After some searching I found this in :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. :-)

The n flag for the :s command has been implemented with Vim 7. Sou you need to upgrade your Vim version. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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