Home

Awesome

<img align="right" width="182" height="355" src="https://i.imgur.com/o5nyLHm.png">

Yoink.vim

Yoink will automatically maintain a history of yanks that you can choose between when pasting.

It provides very similar functionality to nvim-miniyank, YankRing.vim, vim-yankstack or the yank features in vim-easyclip.

Also see here if you prefer watching a video explanation of this plugin instead of the below text.

Mappings

Note that by default Yoink will not affect the way Vim behaves in any way. You have to add one or more of the following maps or enable one of the optional settings to produce an effect.

For example, if you want to add a key to swap the most recent paste around in the yank history:

nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)

nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)

" Also replace the default gp with yoink paste so we can toggle paste in this case too
nmap gp <plug>(YoinkPaste_gp)
nmap gP <plug>(YoinkPaste_gP)

With these mappings, immediately after performing a paste, you can cycle through the history by hitting <c-n> and <c-p>

We also need to override the p and P keys to notify Yoink that a paste has occurred, so that swapping via the <c-n> and <c-p> keys can be enabled. Otherwise paste functionality should be the same as default.

Note that yoink does not support swapping when doing paste in visual mode and so we do not add an xmap for p here. However, the vim-subversive plugin integrates with Yoink and does provide that functionality.

Note that the swap operations above will only affect the current paste and the history order will be unchanged. However - if you do want to permanently cycle through the history, you can do that too:

nmap [y <plug>(YoinkRotateBack)
nmap ]y <plug>(YoinkRotateForward)

Now when you hit [y/]y the current yank will change and you will see a preview of it in the status bar

You might also want to add a map for toggling whether the current paste is formatted or not:

nmap <c-=> <plug>(YoinkPostPasteToggleFormat)

Now, hitting <c-=> after a paste will toggle between formatted and unformatted (equivalent to using the = key). By default pastes will not be formatted until you toggle it afterwards using <c-=> (however you can also change this with the yoinkAutoFormatPaste setting as described below)

Finally, you can also optionally add the following map:

nmap y <plug>(YoinkYankPreserveCursorPosition)
xmap y <plug>(YoinkYankPreserveCursorPosition)

After adding this map, yank will function exactly the same as previously with the one difference being that the cursor position will not change after performing a yank. This can be more useful especially when yanking a large text object such as a paragraph.

Commands

:Yanks - Display the current yank history

:ClearYanks - Delete history. This will reduce the history down to 1 entry taken from the default register.

Settings

You can optionally override the default behaviour with the following settings:

<a id="shada-support"></a>Persistent/Shared History

When g:yoinkSavePersistently is set to 1, the yank history will be saved persistently by taking advantage of Neovim's "ShaDa" feature. Note that since ShaDa support only exists in Neovim this feature is not available for Vim.

You can also use this feature to sync the yank history across multiple running instances of Vim by updating Neovim's shada file. For example, if you execute :wshada in the first instance and then :rshada in the second instance, the second instance will be synced with the yank history in the first instance. If this becomes a common operation you might consider using key bindings for this.

Note also that the ! option must be added to Neovims shada setting for this feature to work. For example: set shada=!,'100,<50,s10,h (see :h 'shada' for details)

System Clipboard

Another feature worth mentioning is that if you have &clipboard set to either unnamed or unnamedplus then Yoink will automatically record yanks that occur outside of Vim. It does this by checking if the system clipboard was changed every time Vim gains focus and if so adding the new yank to the history.

Note that you can disable it by setting g:yoinkSyncSystemClipboardOnFocus to 0 then restarting vim

Integration with vim-cutlass

If you also have vim-cutlass installed then I suggest you set g:yoinkIncludeDeleteOperations to 1. Otherwise the 'cut' operator that you use will not be added to the yank history.

FAQ

If you're using ncm2 for autocomplete you can use this. If you're using something else please create a github issue and we can look at adding a source for that

Just pass a count to the [y command. For example, to rotate to yank #12 as displayed in the :Yanks list, execute 12[y

You can call yoink#manualYank for this. Note that calling this will also set the contents of the default register with the given value. If you just want to add to history without affecting the default register, you can call yoink#addTextToHistory instead

Just use the following mappings:

let g:ctrlp_map=''
nmap <expr> <c-p> yoink#canSwap() ? '<plug>(YoinkPostPasteSwapForward)' : '<Plug>(ctrlp)'

Try adding this to your .vimrc:

nmap <expr> p yoink#canSwap() ? '<plug>(YoinkPostPasteSwapBack)' : '<plug>(YoinkPaste_p)'
nmap <expr> P yoink#canSwap() ? '<plug>(YoinkPostPasteSwapForward)' : '<plug>(YoinkPaste_P)'