Skip to content

Instantly share code, notes, and snippets.

@branquito
Last active December 14, 2015 22:49
Show Gist options
  • Save branquito/5161434 to your computer and use it in GitHub Desktop.
Save branquito/5161434 to your computer and use it in GitHub Desktop.
VIM copy matches into register
function! CopyMatches(reg)
let hits = []
 %s//\=len(add(hits, submatch(0))) ? submatch(0) : ''/ge
let reg = empty(a:reg) ? '+' : a:reg
execute 'let @'.reg.' = join(hits, "\n") . "\n"'
endfunction
command! -register CopyMatches call CopyMatches(<q-reg>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment