This plugin still under development, use at your own risk
The aim of yanky.nvim
is to improve yank and put functionalities for Neovim.
French slogan:
"Vas-y Yanky, c'est bon !" - Yanky Vincent
Or in English:
"Yanky-ki-yay, motherf*cker" - John McYanky
Requires neovim > 0.7.0
.
Install the plugin with your preferred package manager:
-- Lua
use({
"gbprod/yanky.nvim",
config = function()
require("yanky").setup({
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
})
end
})
" Vim Script
Plug 'gbprod/yanky.nvim'
lua << EOF
require("yanky").setup({
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
})
EOF
Yanky comes with the following defaults:
{
ring = {
history_length = 10,
storage = "shada",
sync_with_numbered_registers = true,
},
picker = {
select = {
action = nil, -- nil to use default put action
},
telescope = {
mappings = nil, -- nil to use default mappings
},
},
system_clipboard = {
sync_with_ring = true,
},
highlight = {
on_put = true,
on_yank = true,
timer = 500,
},
preserve_cursor_position = {
enabled = true,
},
}
This plugin contains no default mappings and will have no effect until you add your own maps to it. You should at least set those keymaps:
vim.keymap.set("n", "p", "<Plug>(YankyPutAfter)", {})
vim.keymap.set("n", "P", "<Plug>(YankyPutBefore)", {})
vim.keymap.set("x", "p", "<Plug>(YankyPutAfter)", {})
vim.keymap.set("x", "P", "<Plug>(YankyPutBefore)", {})
vim.keymap.set("n", "gp", "<Plug>(YankyGPutAfter)", {})
vim.keymap.set("n", "gP", "<Plug>(YankyGPutBefore)", {})
vim.keymap.set("x", "gp", "<Plug>(YankyGPutAfter)", {})
vim.keymap.set("x", "gP", "<Plug>(YankyGPutBefore)", {})
Some features requires specific mappings, refer to feature documentation section.
Yank-ring allows cycling throught yank history when putting text (like the Emacs "kill-ring" feature). Yanky automatically maintain a history of yanks that you can choose between when pasting.
vim.api.nvim_set_keymap("n", "<c-n>", "<Plug>(YankyCycleForward)", {})
vim.api.nvim_set_keymap("n", "<c-p>", "<Plug>(YankyCycleBackward)", {})
With these mappings, after performing a paste, you can cycle through the history
by hitting <c-n>
and <c-p>
. Any modifications done after pasting will cancel
the possibility to cycle.
Note that the swap operations above will only affect the current paste and the history will be unchanged.
require("yanky").setup({
ring = {
history_length = 10,
storage = "shada",
sync_with_numbered_registers = true,
},
system_clipboard = {
sync_with_ring = true,
},
})
ring.history_length
Default : 10
Define the number of yanked items that will be saved and used for ring.
ring.storage
Default : shada
Available : shada
or memory
Define the storage mode for ring values.
Using shada
, this will save pesistantly using Neovim ShaDa feature. This means
that history will be persisted between each session of Neovim.
You can also use this feature to sync the yank history across multiple running instances
of Neovim by updating shada file. 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.
Using memory
, each Neovim instance will have his own history and il will be
lost between sessions.
ring.sync_with_numbered_registers
Default : true
History can also be synchronized with numbered registers. Every time the yank history changes the numbered registers 1 - 9 will be updated to sync with the first 9 entries in the yank history. See here for an explanation of why we would want do do this.
system_clipboard.sync_with_ring
Default: true
Yanky can automatically adds to ring history yanks that occurs outside of Neovim.
This works regardless to your &clipboard
setting.
This means, if &clipboard
is set to unnamed
and/or unnamedplus
, if you yank
something outside of Neovim, you can put it immediatly using p
and it will be
added to your yank ring.
If &clipboard
is empty, if you yank something outside of Neovim, this will be
the first value you'll have when cycling through the ring. Basicly, you can do
p
and then <c-p>
to paste yanked text.
You can clear yank history using YankyClearHistory
command.
This allows you to select an entry in your recorded yank history using default
vim.ui.select
neovim prompt (you can use stevearc/dressing.nvim
to customize this) or the awesome telescope.nvim.
It uses the same history as yank ring, so, if you want to increase history size,
just use ring.history_length
option.
To use vim.ui.select
picker, just call YankyRingHistory
command.
To use Telescope
extension, you must first register this extention and then
you can call Telescope yank_history
:
require("telescope").load_extension("yank_history")
If you want dynamic title with register type in Telescope preview window, you
should set dynamic_preview_title
Telescope options to true
.
Default configuration :
require("yanky").setup({
picker = {
select = {
action = nil, -- nil to use default put action
},
telescope = {
mappings = nil, -- nil to use default mappings
},
},
})
picker.select.acion
Default : nil
This define the action that should be done when selecting an item in the
vim.ui.select
prompt. If you let this option to nil
, this will use the
default action : put selected item after cursor.
Available actions:
require("yanky.picker").actions.put("p") -- put after cursor
require("yanky.picker").actions.put("P") -- put before cursor
require("yanky.picker").actions.put("gp") -- put after cursor and leave the cursor after
require("yanky.picker").actions.put("gP") -- put before cursor and leave the cursor after
require("yanky.picker").actions.delete() -- delete entry from yank history
picker.telescope.mappings
Default : nil
This define the mappings available in Telescope. If you let this option to nil
,
this will use the default mappings :
local mapping = require("yanky.telescope.mapping")
require("yanky").setup({
picker = {
telescope = {
mappings = {
default = mapping.put("p"),
i = {
["<c-p>"] = mapping.put("p"),
["<c-k>"] = mapping.put("P"),
["<c-x>"] = mapping.delete(),
},
n = {
p = mapping.put("p"),
P = mapping.put("P"),
d = mapping.delete(),
},
}
}
}
})
Available actions:
require("yanky.telescope.mapping").put("p") -- put after cursor
require("yanky.telescope.mapping").put("P") -- put before cursor
require("yanky.telescope.mapping").put("gp") -- put after cursor and leave the cursor after
require("yanky.telescope.mapping").put("gP") -- put before cursor and leave the cursor after
require("yanky.telescope.mapping").delete() -- delete entry from yank history
NB: More actions and mappings will come.
This will give you a visual feedback on put and yank text by highlighting this.
require("yanky").setup({
highlight = {
on_put = true,
on_yank = true,
timer = 500,
},
})
You can override YankyPut
highlight to change colors.
highlight.on_put
Default : true
Define if highlight put text feature is enabled.
highlight.on_yank
Default : true
Define if highlight yanked text feature is enabled.
ring.timeout
Default : 500
Define the duration of highlight.
By default in Neovim, when yanking text, cursor moves to the start of the yanked text. Could be annoying especially when yanking a large text object such as a paragraph or a large text object.
With this feature, yank will function exactly the same as previously with the one difference being that the cursor position will not change after performing a yank.
vim.keymap.set("n", "y", "<Plug>(YankyYank)", {})
vim.keymap.set("x", "y", "<Plug>(YankyYank)", {})
require("yanky").setup({
preserve_cursor_position = {
enabled = true,
},
})
preserve_cursor_position.enable
Default : true
Define if cursor position should be preserved on yank. This works only if mappings has been defined.
Description | Group | Default |
---|---|---|
Highlight color for put text | YankyPut | link to Search |
Highlight color for yanked text | YankyYanked | link to Search |
To enable gbprod/substitute.nvim swap when performing a substitution, you can add this to your setup:
require("substitute").setup({
on_substitute = function(event)
require("yanky").init_ring("p", event.register, event.count, event.vmode:match("[vV]"))
end,
})
This plugin is mostly a lua version of svermeulen/vim-yoink awesome plugin.
Other inspiration :
Thanks to m00qek lua plugin template.