Wednesday, 15 February 2012

unix - Copy the highlighted pattern in gvim -



unix - Copy the highlighted pattern in gvim -

lets say, highlighted (matched) text nowadays in brackets using

/(.*)

now, how re-create highlighted text (i.e matching pattern, not entire line) buffer, paste where.

multiple approaches presented in this vim tips wiki page. simplest approach next custom command:

function! copymatches(reg) allow hits = [] %s//\=len(add(hits, submatch(0))) ? submatch(0) : ''/ge allow reg = empty(a:reg) ? '+' : a:reg execute 'let @'.reg.' = join(hits, "\n") . "\n"' endfunction command! -register copymatches phone call copymatches(<q-reg>)

unix vim

No comments:

Post a Comment