Capture the number of 'yes' clicks in a substitute command with confirmation?

≯℡__Kan透↙ 提交于 2019-12-20 05:58:23

问题


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:


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.



来源:https://stackoverflow.com/questions/34262677/capture-the-number-of-yes-clicks-in-a-substitute-command-with-confirmation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!