How can I make vim remember past yanks? (Or configure YankRing to do less.)

StackOverflow https://stackoverflow.com/questions/9167681

  •  26-04-2021
  •  | 
  •  

سؤال

When I delete something in vim, it's added to the numbered registers. The last item I yanked is in register 0. How can I get vim to automatically remember the last 10 yanks too?


I've tried YankRing, but it changes too much of vim behavior. An alternative phrasing of this question: How can I configure YankRing so it only adds the Ctrl-n/Ctrl-p behavior after pasting (to cycle through previous yanks)?

I often yank a word, visual select another word, paste, visual select another word, paste. Without YankRing, the last paste puts the first selected word. With YankRing, it pastes the same word again. (This is just one example.)

Here are some of my yankring settings. As you can see, I've looked through the YankRing docs to disable as many options as I can to revert to normal vim behavior.

" Some settings to try to get yank ring to not mess with default vim
" functionality so much.
let g:yankring_manage_numbered_reg = 0
let g:yankring_clipboard_monitor = 0
let g:yankring_paste_check_default_buffer = 0

" Don't let yankring use f, t, /. It doesn't record them properly in macros
" and that's my most common use. Yankring also blocks macros of macros (it
" prompts for the macro register), but removing @ doesn't fix that :(
let g:yankring_zap_keys = ''

" Disable yankring for regular p/P. This preserves vim's normal behavior, but
" I can still use C-p/C-n to cycle through yankring.
let g:yankring_paste_n_bkey = ''
let g:yankring_paste_n_akey = ''
let g:yankring_paste_v_key = ''
هل كانت مفيدة؟

المحلول

You could try plugin yankstack: a lightweight implementation of the Emacs ‘kill ring’ for Vim.

Its description states that ‘This plugin is intended to be a simpler alternative to the yankring plugin’.

نصائح أخرى

You can use the " command to specify a register for yanking. From :help quote:

                                                        *quote*
"{a-zA-Z0-9.%#:-"}      Use register {a-zA-Z0-9.%#:-"} for next delete, yank
                        or put (use uppercase character to append with
                        delete and yank) ({.%#:} only work with put).

Turns out there are undocumented options (I found by typing :echo g:yankring_paste_<Tab>).

let g:yankring_paste_v_bkey = ''
let g:yankring_paste_v_akey = ''

Now my yank, visual paste, visual paste works as expected. (We'll see if there are other bits that change default vim behavior.)

You can just do d<movement>P in normal mode and it will delete and then paste what you just deleted, plus the numbered registers get shifted if you move a line or more.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top