2
%s///n

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

How to copy this output to a register?

statox
  • 49,782
  • 19
  • 148
  • 225
gov
  • 29
  • 2

1 Answers1

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

Hotschke
  • 4,740
  • 26
  • 37
  • Would :let @a=execute(@:) work as well? – D. Ben Knoble Dec 04 '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 09 '18 at 10:24