-
-
Save neumachen/ba611afa236010d4ab104fc0e35e521b to your computer and use it in GitHub Desktop.
A simple yankring. A much needed improvement on the numbered registers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! yankring#reset() abort | |
let s:yankring = [] | |
for l:i in range(1, 9) | |
execute 'let l:contents = @' . l:i | |
call add(s:yankring, l:contents) | |
endfor | |
endfunction | |
call yankring#reset() | |
function! yankring#yank(contents) abort | |
call insert(s:yankring, join(a:contents, "\<C-j>")) | |
while len(s:yankring) > 9 | |
call remove(s:yankring, -1) | |
endwhile | |
call yankring#sync() | |
endfunction | |
function! yankring#sync() abort | |
messages clear | |
for l:n in range(len(s:yankring)) | |
execute 'let @' . l:n . ' = "' . escape(s:yankring[l:n], '"') . '"' | |
endfor | |
endfunction | |
augroup yankring | |
autocmd! | |
autocmd TextYankPost * if empty(v:event['regname']) | call yankring#yank(v:event['regcontents']) | endif | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment