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

后端 未结 1 525
旧巷少年郎
旧巷少年郎 2021-01-27 08:21

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)?         


        
相关标签:
1条回答
  • 2021-01-27 08:51

    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.

    0 讨论(0)
提交回复
热议问题