2
%s///n

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

How to copy this output to a register?

2
  • Not an exact duplicate but a very related question here
    – statox
    Commented Dec 4, 2018 at 13:38
  • take a look at this plugin, it may already contain what you want
    – doraemon
    Commented Dec 5, 2018 at 9:18

1 Answer 1

4
: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

<Ctrl-r>=execute('<Ctrl-r>:')

Relevant Links

2
  • Would :let @a=execute(@:) work as well?
    – D. Ben Knoble
    Commented Dec 4, 2018 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
    Commented Dec 9, 2018 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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