show number of matching pattern like 102 matches on 102 lines.

How to copy this output to a register?

  • Not an exact duplicate but a very related question here
    – statox
    Dec 4 '18 at 13:38
  • take a look at this plugin, it may already contain what you want
    – doraemon
    Dec 5 '18 at 9:18
:redir @a | %s///n | redir END

An alternative is

:let @a=execute('%s///n')

If %s///n is the last command, you can type:

:let @a=execute('<Ctrl-r>:')

or if you want to paste it immediately into the document, switch to insert mode and type


Relevant Links

  • Would :let @a=execute(@:) work as well?
    – D. Ben Knoble
    Dec 4 '18 at 14:38
  • Should work as well. However, you have no immediate feedback what in @: is. Some people develop the habit of pressing :w without thinking about it and 'mess up' the register @:. Pressing <C-r>: tells you immediately what you gonna execute.
    – Hotschke
    Dec 9 '18 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.