vim - Can I search all my registers to paste a value -
let's i'm restructuring text including line contains text "log". after bit more editing, want paste log line, in far-off register. there way search registers first contains term "log" , paste contents?
the following should job:
function! searchandpastereg() let l:pattern = input('reg search: ') if l:pattern == '' | return | endif l:i in range(1, 9) if match(eval('@'.l:i), l:pattern) != -1 execute printf('normal "%i]p', l:i) return endif endfor redraw | echo 'pattern not found' endf nnoremap <silent> ]r :call searchandpastereg()<cr>
i'm not sure if talking numbered registers, or registers. if want search regs, extend range list containing desired register names, this:
function! searchandpastereg() let l:pattern = input('reg search: ') if l:pattern == '' | return | endif let l:regs = range(char2nr('1'), char2nr('9')) call map(extend(l:regs, range(char2nr('a'), char2nr('z'))), 'nr2char(v:val)') l:reg in l:regs if match(eval('@'.l:reg), l:pattern) != -1 execute printf('normal "%s]p', l:reg) return endif endfor redraw | echo 'pattern not found' endf nnoremap <silent> ]r :call searchandpastereg()<cr>
Comments
Post a Comment