11

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 = ''
idbrii
  • 10,975
  • 5
  • 66
  • 107
  • I also stopped using yankring because I felt it messing with some vim defaults that I like. It would be nice just having the ctrl-n/ctrl-p but now I have also started using ctrlp plugin so that would probably conflict with yankring. – skeept Feb 06 '12 at 23:09
  • @skeept: Why don't you change the CtrlP map? I did that and I use yankstack and CtrlP together. – idbrii Jul 28 '12 at 02:07

4 Answers4

14

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’.

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
mMontu
  • 8,983
  • 4
  • 38
  • 53
  • While I used and liked yankstack for years (thanks for the recommendation!), I now prefer unite.vim history/yank source (neoyank.vim) which polls your registers instead of remapping keys. – idbrii Nov 15 '17 at 21:41
  • @idbrii good to know, I've also stopped using yankstack. I'll check unite.vim -- actually [its github](https://github.com/shougo/unite.vim) it may be better to use Denite.nvim. – mMontu Nov 16 '17 at 15:42
5

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).
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • While that works in the one case I mentioned, vim's default behavior is not restored. Also, I'd have to type " before every yank command. – idbrii Feb 06 '12 at 21:45
  • Ok. I don't know anything about YankRing, so I was just answering the first part of your question. – Greg Hewgill Feb 06 '12 at 21:49
  • Ah, ok. Clarified question: I want it to be automatic and to remember lots of yanks. – idbrii Feb 06 '12 at 21:52
1

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.

mondaugen
  • 425
  • 5
  • 12
1

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.)

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • If you're still interested, it also messes up the '.' command in a manner that interferes with working of repeat.vim. Also, if I remember correctly, it remaps . Didn't explore much beyond that. The first issue was sufficient to make me switch to yankstack – kshenoy Mar 10 '12 at 06:52