Capture the number of 'yes' clicks in a su

2019-03-05 03:22发布

Is it possible to capture the number of 'yes' clicks in a substitute command with confirmation?

p.e.

:%s/foo/bar/gc
replace with bar (y/n/a/q/l/^E/^Y)?

number of y clicks = ?

1条回答
疯言疯语
2楼-- · 2019-03-05 03:36

If you want to know how many substitutions were done (the number of y), after all occurrences confirmation were asked, you will see X substitutusions on Y lines, the X is what you want.

If you are writing a script and you want to get the number in your script. You can either implement this counter in your function, or before the :s/../../gc, redir @x after all substitutions were done, redir END. Read @x, take the last line, extract ^\d\+, that would be the number.

查看更多
登录 后发表回答