Feature request: substitute uses the 'n' flag

0 views
Skip to first unread message

David Fishburn

unread,
Nov 18, 2008, 9:56:08 AM11/18/08
to vim_use
Vim 7.2

I was reading this section:

:h count-items
To count how often any pattern occurs in the current buffer use the substitute
command and add the 'n' flag to avoid the substitution. The reported number
of substitutions is the number of items.
:%s/./&/gn characters

For the substitute function, it looks like only 'g' is supported
:h substitute()
When {flags} is "g", all matches of {pat} in {expr} are
replaced. Otherwise {flags} should be "".


It would be nice if substitute also allowed the 'n' flag.
And in that case, do not return the string, but return the count.

For example:
echo substitute('dadada', 'd', '&', 'g')
dadada

echo substitute('dadada', 'd', '&', 'gn')
3

Since the 'n' switch says "do not perform the sub" it seems reasonable
we could get something useful back.

Dave

Reply all
Reply to author
Forward
0 new messages