2
%s///n

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 – Liu Sha Dec 5 '18 at 9:18
3
: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

  • 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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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