Giter Site home page Giter Site logo

yanky.nvim's Introduction

🍃 yanky.nvim

Lua GitHub Workflow Status

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

✨ Features

  • 🖇️ Yank-ring
  • 📜 Yank history picker
  • 💡 Highlight put and yanked text
  • ⤵️ Preserve cursor position on yank
  • ⭐ Special put
  • ⚓ Text object

⚡️ Requirements

Requires neovim > 0.9.0.

📦 Installation

Install the plugin with your preferred package manager:

{
  "gbprod/yanky.nvim",
  opts = {
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
  },
}
More complete setup
{
  "gbprod/yanky.nvim",
  dependencies = {
    { "kkharji/sqlite.lua" }
  },
  opts = {
    ring = { storage = "sqlite" },
  },
  keys = {
    { "<leader>p", function() require("telescope").extensions.yank_history.yank_history({ }) end, desc = "Open Yank History" },
    { "y", "<Plug>(YankyYank)", mode = { "n", "x" }, desc = "Yank text" },
    { "p", "<Plug>(YankyPutAfter)", mode = { "n", "x" }, desc = "Put yanked text after cursor" },
    { "P", "<Plug>(YankyPutBefore)", mode = { "n", "x" }, desc = "Put yanked text before cursor" },
    { "gp", "<Plug>(YankyGPutAfter)", mode = { "n", "x" }, desc = "Put yanked text after selection" },
    { "gP", "<Plug>(YankyGPutBefore)", mode = { "n", "x" }, desc = "Put yanked text before selection" },
    { "<c-p>", "<Plug>(YankyPreviousEntry)", desc = "Select previous entry through yank history" },
    { "<c-n>", "<Plug>(YankyNextEntry)", desc = "Select next entry through yank history" },
    { "]p", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put indented after cursor (linewise)" },
    { "[p", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put indented before cursor (linewise)" },
    { "]P", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put indented after cursor (linewise)" },
    { "[P", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put indented before cursor (linewise)" },
    { ">p", "<Plug>(YankyPutIndentAfterShiftRight)", desc = "Put and indent right" },
    { "<p", "<Plug>(YankyPutIndentAfterShiftLeft)", desc = "Put and indent left" },
    { ">P", "<Plug>(YankyPutIndentBeforeShiftRight)", desc = "Put before and indent right" },
    { "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)", desc = "Put before and indent left" },
    { "=p", "<Plug>(YankyPutAfterFilter)", desc = "Put after applying a filter" },
    { "=P", "<Plug>(YankyPutBeforeFilter)", desc = "Put before applying a filter" },
  },
}
-- Lua
use("gbprod/yanky.nvim")
require("yanky").setup({
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
})

⚙️ Configuration

Yanky comes with the following defaults:

{
  ring = {
    history_length = 100,
    storage = "shada",
    storage_path = vim.fn.stdpath("data") .. "/databases/yanky.db", -- Only for sqlite storage
    sync_with_numbered_registers = true,
    cancel_event = "update",
    ignore_registers = { "_" },
    update_register_on_cycle = false,
  },
  picker = {
    select = {
      action = nil, -- nil to use default put action
    },
    telescope = {
      use_default_mappings = true, -- if default mappings should be used
      mappings = nil, -- nil to use default mappings or no mappings (see `use_default_mappings`)
    },
  },
  system_clipboard = {
    sync_with_ring = true,
  },
  highlight = {
    on_put = true,
    on_yank = true,
    timer = 500,
  },
  preserve_cursor_position = {
    enabled = true,
  },
  textobj = {
   enabled = true,
  },
}

⌨️ Mappings

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 for yank ring usage:

vim.keymap.set({"n","x"}, "p", "<Plug>(YankyPutAfter)")
vim.keymap.set({"n","x"}, "P", "<Plug>(YankyPutBefore)")
vim.keymap.set({"n","x"}, "gp", "<Plug>(YankyGPutAfter)")
vim.keymap.set({"n","x"}, "gP", "<Plug>(YankyGPutBefore)")

vim.keymap.set("n", "<c-p>", "<Plug>(YankyPreviousEntry)")
vim.keymap.set("n", "<c-n>", "<Plug>(YankyNextEntry)")

And those keymaps for tpope/vim-unimpaired like usage:

vim.keymap.set("n", "]p", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[p", "<Plug>(YankyPutIndentBeforeLinewise)")
vim.keymap.set("n", "]P", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[P", "<Plug>(YankyPutIndentBeforeLinewise)")

vim.keymap.set("n", ">p", "<Plug>(YankyPutIndentAfterShiftRight)")
vim.keymap.set("n", "<p", "<Plug>(YankyPutIndentAfterShiftLeft)")
vim.keymap.set("n", ">P", "<Plug>(YankyPutIndentBeforeShiftRight)")
vim.keymap.set("n", "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)")

vim.keymap.set("n", "=p", "<Plug>(YankyPutAfterFilter)")
vim.keymap.set("n", "=P", "<Plug>(YankyPutBeforeFilter)")

Some features requires specific mappings, refer to feature documentation section.

🖇️ Yank-ring

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.

⌨️ Mappings

vim.keymap.set("n", "<c-p>", "<Plug>(YankyPreviousEntry)")
vim.keymap.set("n", "<c-n>", "<Plug>(YankyNextEntry)")

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.

⚙️ Configuration

require("yanky").setup({
  ring = {
    history_length = 100,
    storage = "shada",
    sync_with_numbered_registers = true,
    cancel_event = "update",
    ignore_registers = { "_" },
    update_register_on_cycle = false,
  },
  system_clipboard = {
    sync_with_ring = true,
  },
})

ring.history_length

Default : 100

Define the number of yanked items that will be saved and used for ring.

ring.storage

Default : shada

Available : shada, sqlite 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.

If you want to use sqlite as storage, you must add kkharji/sqlite.lua as dependency:

use({
  "gbprod/yanky.nvim",
  requires = { "kkharji/sqlite.lua" }
})

Sqlite is more reliable than ShaDa but requires more dependencies. You can change the storage path using ring.storage_path option.

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.

ring.cancel_event

Default: update

Define the event used to cancel ring activation. update will cancel ring on next buffer update, move will cancel ring when moving cursor or content changed.

ring.ignore_registers

Default: { "_" }

Define registeres to be ignored. By default the black hole register is ignored.

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.

ring.update_register_on_cycle

Default: false

Using the update_register_on_cycle option, when you cycle through the ring, the contents of the register used to update will be updated with the last content cycled.

Commands

You can clear yank history using YankyClearHistory command.

📜 Yank history picker

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.

See Integrations to have a completion with nvim-cmp.

Yank history completions

Using nvim-cmp and cmp_yanky, you can also get suggestions from your yank history as you type in insert mode.

demonstration showcasing cmp-yanky

⚙️ Configuration

To use vim.ui.select picker, just call YankyRingHistory command.

To use the yank_history Telescope picker, register yank_history as a Telescope extension in your Neovim config file.

:lua require("telescope").load_extension("yank_history")

After loading the extension, you can access the picker by running:

:Telescope yank_history

Or:

:lua require("telescope").extensions.yank_history.yank_history()

Set the Telescope option dynamic_preview_title to true if you want your Telescope preview window to have a dynamic title showing the register's type.

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

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
require("yanky.picker").actions.set_register(regname) -- fill register with selected value
require("yanky.picker").actions.put_and_set_register("p", regname) -- put and fill register with selected value

picker.telescope.use_default_mappings

Default : true

This define if default Telescope mappings should be use.

If you let this option to true, this will use the default mappings :

local utils = require("yanky.utils")
local mapping = require("yanky.telescope.mapping")

require("yanky").setup({
  picker = {
    telescope = {
      mappings = {
        default = mapping.put("p"),
        i = {
          ["<c-g>"] = mapping.put("p"),
          ["<c-k>"] = mapping.put("P"),
          ["<c-x>"] = mapping.delete(),
          ["<c-r>"] = mapping.set_register(utils.get_default_register()),
        },
        n = {
          p = mapping.put("p"),
          P = mapping.put("P"),
          d = mapping.delete(),
          r = mapping.set_register(utils.get_default_register())
        },
      }
    }
  }
})

picker.telescope.mappings

Default : nil

This define or overrides the mappings available in Telescope.

If you set use_default_mappings to true, mappings will be merged with default mappings.

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
require("yanky.telescope.mapping").set_register(regname) -- fill register {regname} with selected value

You can also use any of available special puts like this:

require("yanky.telescope.mapping").special_put("{{ name of the special put }}")

-- eg.
require("yanky.telescope.mapping").special_put("YankyPutAfterCharwiseJoined")

💡 Highlight put and yanked text

This will give you a visual feedback on put and yank text by highlighting this.

### Configuration

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.

highlight.timer

Default : 500

Define the duration of highlight.

⤵️ Preserve cursor position on yank

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.

⌨️ Mappings

vim.keymap.set({"n","x"}, "y", "<Plug>(YankyYank)")

⚙️ Configuration

require("yanky").setup({
  preserve_cursor_position = {
    enabled = true,
  },
})

preserve_cursor_position.enabled

Default : true

Define if cursor position should be preserved on yank. This works only if mappings has been defined.

⭐ Special put

Yanky comes with special put moves (inspired by tpope/vim-unimpaired):

  • Linewise put: this will force put above or below the current line ;
  • Shift right/left put: will put above or below the current line and increasing or decreasing indent ;
  • Filter put: will put above or below the current line and reindenting.

⌨️ Mappings

For basic usage (like with tpope/vim-unimpaired), you can use those bindings:

vim.keymap.set("n", "]p", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[p", "<Plug>(YankyPutIndentBeforeLinewise)")
vim.keymap.set("n", "]P", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[P", "<Plug>(YankyPutIndentBeforeLinewise)")

vim.keymap.set("n", ">p", "<Plug>(YankyPutIndentAfterShiftRight)")
vim.keymap.set("n", "<p", "<Plug>(YankyPutIndentAfterShiftLeft)")
vim.keymap.set("n", ">P", "<Plug>(YankyPutIndentBeforeShiftRight)")
vim.keymap.set("n", "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)")

vim.keymap.set("n", "=p", "<Plug>(YankyPutAfterFilter)")
vim.keymap.set("n", "=P", "<Plug>(YankyPutBeforeFilter)")

To go further, Plug mappings are constructed like this: Yanky(put-type)(modifier)(rewriter).

put-type can be:

  • PutAfter: put after your cursor (as p key) ;
  • PutBefore: put before your cursor (as P key) ;
  • GPutAfter: like PutAfter but leave the cursor after the new text (as gp key) ;
  • GPutBefore: like PutBefore but leave the cursor after the new text (as gP key) ;
  • PutIndentAfter: like PutAfter but adjust the indent to the current line (as ]p key) ;
  • PutIndentBefore: like PutBefore but adjust the indent to the current line (as [p key) ;

modifier (optional) can be:

  • Linewise: put in linewise mode ;
  • Charwise: put in charwise mode ;
  • Blockwise: put in blockwise mode ;
  • ShiftRight: increase indent ;
  • ShiftLeft: decrease indent.

rewriter (optional) can be:

  • Joined: put lines trimed and joined.
All special puts
<Plug>(YankyPutAfter)
<Plug>(YankyPutAfterBlockwise)
<Plug>(YankyPutAfterBlockwiseJoined)
<Plug>(YankyPutAfterCharwise)
<Plug>(YankyPutAfterCharwiseJoined)
<Plug>(YankyPutAfterFilter)
<Plug>(YankyPutAfterFilterJoined)
<Plug>(YankyPutAfterJoined)
<Plug>(YankyPutAfterLinewise)
<Plug>(YankyPutAfterLinewiseJoined)
<Plug>(YankyPutAfterShiftLeft)
<Plug>(YankyPutAfterShiftLeftJoined)
<Plug>(YankyPutAfterShiftRight)
<Plug>(YankyPutAfterShiftRightJoined)
<Plug>(YankyPutBefore)
<Plug>(YankyPutBeforeBlockwise)
<Plug>(YankyPutBeforeBlockwiseJoined)
<Plug>(YankyPutBeforeCharwise)
<Plug>(YankyPutBeforeCharwiseJoined)
<Plug>(YankyPutBeforeFilter)
<Plug>(YankyPutBeforeFilterJoined)
<Plug>(YankyPutBeforeJoined)
<Plug>(YankyPutBeforeLinewise)
<Plug>(YankyPutBeforeLinewiseJoined)
<Plug>(YankyPutBeforeShiftLeft)
<Plug>(YankyPutBeforeShiftLeftJoined)
<Plug>(YankyPutBeforeShiftRight)
<Plug>(YankyPutBeforeShiftRightJoined)
<Plug>(YankyGPutAfter)
<Plug>(YankyGPutAfterBlockwise)
<Plug>(YankyGPutAfterBlockwiseJoined)
<Plug>(YankyGPutAfterCharwise)
<Plug>(YankyGPutAfterCharwiseJoined)
<Plug>(YankyGPutAfterFilter)
<Plug>(YankyGPutAfterFilterJoined)
<Plug>(YankyGPutAfterJoined)
<Plug>(YankyGPutAfterLinewise)
<Plug>(YankyGPutAfterLinewiseJoined)
<Plug>(YankyGPutAfterShiftLeft)
<Plug>(YankyGPutAfterShiftLeftJoined)
<Plug>(YankyGPutAfterShiftRight)
<Plug>(YankyGPutAfterShiftRightJoined)
<Plug>(YankyGPutBefore)
<Plug>(YankyGPutBeforeBlockwise)
<Plug>(YankyGPutBeforeBlockwiseJoined)
<Plug>(YankyGPutBeforeCharwise)
<Plug>(YankyGPutBeforeCharwiseJoined)
<Plug>(YankyGPutBeforeFilter)
<Plug>(YankyGPutBeforeFilterJoined)
<Plug>(YankyGPutBeforeJoined)
<Plug>(YankyGPutBeforeLinewise)
<Plug>(YankyGPutBeforeLinewiseJoined)
<Plug>(YankyGPutBeforeShiftLeft)
<Plug>(YankyGPutBeforeShiftLeftJoined)
<Plug>(YankyGPutBeforeShiftRight)
<Plug>(YankyGPutBeforeShiftRightJoined)
<Plug>(YankyPutIndentAfter)
<Plug>(YankyPutIndentAfterBlockwise)
<Plug>(YankyPutIndentAfterBlockwiseJoined)
<Plug>(YankyPutIndentAfterCharwise)
<Plug>(YankyPutIndentAfterCharwiseJoined)
<Plug>(YankyPutIndentAfterFilter)
<Plug>(YankyPutIndentAfterFilterJoined)
<Plug>(YankyPutIndentAfterJoined)
<Plug>(YankyPutIndentAfterLinewise)
<Plug>(YankyPutIndentAfterLinewiseJoined)
<Plug>(YankyPutIndentAfterShiftLeft)
<Plug>(YankyPutIndentAfterShiftLeftJoined)
<Plug>(YankyPutIndentAfterShiftRight)
<Plug>(YankyPutIndentAfterShiftRightJoined)
<Plug>(YankyPutIndentBefore)
<Plug>(YankyPutIndentBeforeBlockwise)
<Plug>(YankyPutIndentBeforeBlockwiseJoined)
<Plug>(YankyPutIndentBeforeCharwise)
<Plug>(YankyPutIndentBeforeCharwiseJoined)
<Plug>(YankyPutIndentBeforeFilter)
<Plug>(YankyPutIndentBeforeFilterJoined)
<Plug>(YankyPutIndentBeforeJoined)
<Plug>(YankyPutIndentBeforeLinewise)
<Plug>(YankyPutIndentBeforeLinewiseJoined)
<Plug>(YankyPutIndentBeforeShiftLeft)
<Plug>(YankyPutIndentBeforeShiftLeftJoined)
<Plug>(YankyPutIndentBeforeShiftRight)
<Plug>(YankyPutIndentBeforeShiftRightJoined)

⚓ Text object

Yanky comes with a text object corresponding to last put text. To use it, you have to enable it in settings and set a keymap.

⚙️ Configuration

require("yanky").setup({
  textobj = {
    enabled = true,
  },
})

⌨️ Mappings

vim.keymap.set({ "o", "x" }, "lp", function()
  require("yanky.textobj").last_put()
end, {})

🎨 Colors

Description Group Default
Highlight color for put text YankyPut link to Search
Highlight color for yanked text YankyYanked link to Search

🤝 Integrations

gbprod/substitute.nvim

To enable gbprod/substitute.nvim swap when performing a substitution, you can add this to your setup:

require("substitute").setup({
  on_substitute = require("yanky.integration").substitute(),
})
hrsh7th/nvim-cmp

Using hrsh7th/nvim-cmp and chrisgrieser/cmp_yanky, you can also get suggestions from your yank history as you type in insert mode.

showcasing cmp-yanky
anuvyklack/hydra.nvim

To work with anuvyklack/hydra.nvim only setup / mapping when yanky is activated, you can add this to your setup:

local Hydra = require("hydra")

local function t(str)
  return api.nvim_replace_termcodes(str, true, true, true)
end

local yanky_hydra = Hydra({
  name = "Yank ring",
  mode = "n",
  heads = {
    { "p", "<Plug>(YankyPutAfter)", { desc = "After" } },
    { "P", "<Plug>(YankyPutBefore)", { desc = "Before" } },
    { "<c-p>", "<Plug>(YankyPreviousEntry)", { private = true, desc = "" } },
    { "<c-n>", "<Plug>(YankyNextEntry)", { private = true, desc = "" } },
  },
})

-- choose/change the mappings if you want
for key, putAction in pairs({
  ["p"] = "<Plug>(YankyPutAfter)",
  ["P"] = "<Plug>(YankyPutBefore)",
  ["gp"] = "<Plug>(YankyGPutAfter)",
  ["gP"] = "<Plug>(YankyGPutBefore)",
}) do
  vim.keymap.set({ "n", "x" }, key, function()
    vim.fn.feedkeys(t(putAction))
    yanky_hydra:activate()
  end)
end

-- choose/change the mappings if you want
for key, putAction in pairs({
  ["]p"] = "<Plug>(YankyPutIndentAfterLinewise)",
  ["[p"] = "<Plug>(YankyPutIndentBeforeLinewise)",
  ["]P"] = "<Plug>(YankyPutIndentAfterLinewise)",
  ["[P"] = "<Plug>(YankyPutIndentBeforeLinewise)",

  [">p"] = "<Plug>(YankyPutIndentAfterShiftRight)",
  ["<p"] = "<Plug>(YankyPutIndentAfterShiftLeft)",
  [">P"] = "<Plug>(YankyPutIndentBeforeShiftRight)",
  ["<P"] = "<Plug>(YankyPutIndentBeforeShiftLeft)",

  ["=p"] = "<Plug>(YankyPutAfterFilter)",
  ["=P"] = "<Plug>(YankyPutBeforeFilter)",
}) do
  vim.keymap.set("n", key, function()
    vim.fn.feedkeys(t(putAction))
    yanky_hydra:activate()
  end)
end

🎉 Credits

This plugin is mostly a lua version of svermeulen/vim-yoink awesome plugin.

Other inspiration :

yanky.nvim's People

Contributors

aceforeverd avatar andrewmustea avatar anuvyklack avatar bagohart avatar bekicot avatar chrisgrieser avatar delphinus avatar folke avatar gbprod avatar hioz avatar hungryjoe avatar marcosven avatar mariasolos avatar sazk07 avatar tj-moody avatar wuelnerdotexe avatar xeluxee avatar younger-1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yanky.nvim's Issues

Feature Request: Preview

Good day! I love this plugin and use it every day but there is 1 feature that I think would push it over the top: previews in the Ring History similar to neoclip

I do not know how difficult that would be with telescope but I think it'd be great!

Thanks again for the great work on this plugin!

Feature request: remember yank ring position on next paste

I generally find that when I use the yank ring and paste mutliple times in a row I usually want to paste from the same position in the yank ring. Therefore I would personally like if the yank ring remembered my position between pastes. For example, if I yank the word foo, then yank bar, then paste with <Plug>(YankyPutAfter) (bar) and then cycle with <Plug>(YankyCycleForward) (foo), the next time I paste I would like yanky to paste foo again (currently it would paste bar).

If anything new is added to the paste ring (i.e. if I yank something) yanky would reset the ring position to the latest yanked item. What do you think about this idea?

`YankyGPutIndent*`

Would it be possible to also add actions like YankyGPutIndentAfter and YankyGPutIndentBefore?

conditional map `<c-n> & <c-p`

so I want e.g <c-n> to fallback to normal ctrl_n or something if it is not in a paste/cycle state

I write something like

local function map_c_n()
  if require('yanky').ring.state then
    require('yanky').cycle(1)
  else
    vim.cmd[[execute "normal! \<c-n>"]]
  end
end

to remap <c-n> but it seems ring.state can only back to nil if line content is changed. Will it possible back to nil also if cursor moved out of pasted line ?

Hangs Neovim

Kooha-07-24-2022-21-37-55.mp4

I'm able to reproduce this even with minconfig:

-- nvim --clean -u mini.lua mini.lua
vim.o.packpath = '~/.local/share/nvim/site'

vim.cmd 'packadd yanky'
require('yanky').setup({})

I'm using nvim 7.2 and Fedora 36 with Wayland.

yanky.nvim causes Neovim freezing when system goes sleep

yanky.nvim config:

require('yanky').setup({})

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)', {})

vim.keymap.set('n', '<c-n>', '<Plug>(YankyCycleForward)', {})
vim.keymap.set('n', '<c-p>', '<Plug>(YankyCycleBackward)', {})

require("telescope").load_extension("yank_history")

Neovim version:

NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

OS info:

OS: Arch Linux x86_64
Kernel: 5.18.1-arch1-1
DE: Plasma 5.24.5
Graphics platform: X11

Clipboard error : Target STRING not available

I get the message Clipboard error : Target STRING not available when starting neovim with this plugin setup. The message does not appear when I disable yanky in my config.

I found this issue on neovims repo: neovim/neovim#2642

Where the last comment states:

On the off chance someone else still sees this error, you could be using an older yank plugin like https://github.com/svermeulen/vim-easyclip

Moving to something newer like https://github.com/svermeulen/vim-cutlass will avoid these issues.

So I guess there is some configuration that needs to be done plugin side to avoid this

[Bug Report]: nvim freezing when opening files

Introduction

Hello gbprod! Big fan of your plugin series (substitute.nvim , cutlass.nvim, yanky.nvim (not so much due to this annoying bug)).

Since I have more than 100 plugins it's very difficult to isolate the cause of this nvim freezing. Initially it was only a hunch that yanky was the cause, since I can't reliably reproduce this freezing. So I disabled yanky and went about using nvim, no problem. Then I enabled yanky and nvim would freeze randomly. By freeze I mean I can't enter nvim. nvim would freeze while opening files.

Videos

I tried my best to isolate the cause for more than a month, and I finally captured it in video:

simplescreenrecorder-2022-06-08_01.43.27.mp4
  1. vim init.lua (I have aliased vim with nvim)
  2. It opened up init.lua without any issue
  3. enabled yanky.nvim
  4. exit nvim and vim init.lua again
  5. nvim froze

Another video:

simplescreenrecorder-2022-06-08_01.41.17-2.mp4
  1. not shown in video: yanky enabled. nvim used to freeze randomly but this morning it freezes every time with yanky enabled
  2. vim -u NONE init.lua to enter nvim and disable yanky
  3. successfully entered nvim without freezing

Description

I suspect this freezing is due to xclip. nvim used to freeze randomly but this morning it froze every time. The only change I have is manually compiling xclip from xclip/master. I had some other issues with xclip unrelated to nvim so tested with compiling the latest version. I used to use xclip 0.13.

Interestingly, I tried yoink.vim and this random freezing also happened. With the advice from vim-yoink/issues/16, I used xsel instead of xclip and this random freezing seemed to happen less:

severe freezing like videos above: compiling from xclip/master

random freezing here and there: xclip version 0.13 or xsel

The reason I used yanky is for its yank-ring feature. Because, sigh, my nvim would freeze randomly with the following:

  1. yank buffer content
  2. close nvim
  3. paste yanked content to another nvim instance
  4. freeze

I couldn't capture the above in video because it happens randomly.

nvim config:

NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

OS: Manjaro Linux
Kernel: 5.15.41-1-MANJARO

I tried compiling nvim to the latest 0.8 version and this freezing still happened.

Any help is much appreciated. Thank you again for creating this awesome nvim plugin series:)

Issue with `:telescope yank_history`

:telescope yank_history works but ...

image

when I select an entry from the list I get this error.

E5108: Error executing lua .../packer/start/yanky.nvim/lua/yanky/telescope/mapping.lua:11: attempt to call field 'make_put_handler' (a nil value)
stack traceback:
        .../packer/start/yanky.nvim/lua/yanky/telescope/mapping.lua:11: in function 'run_replace_or_original'
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:242: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk

My Settings:

require("yanky").setup({
  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,
  },
})

vim.api.nvim_set_keymap("n", "p", "<Plug>(YankyPutAfter)", {})
vim.api.nvim_set_keymap("n", "P", "<Plug>(YankyPutBefore)", {})
vim.api.nvim_set_keymap("x", "p", "<Plug>(YankyPutAfter)", {})
vim.api.nvim_set_keymap("x", "P", "<Plug>(YankyPutBefore)", {})
vim.api.nvim_set_keymap("n", "gp", "<Plug>(YankyGPutAfter)", {})
vim.api.nvim_set_keymap("n", "gP", "<Plug>(YankyGPutBefore)", {})
vim.api.nvim_set_keymap("x", "gp", "<Plug>(YankyGPutAfter)", {})
vim.api.nvim_set_keymap("x", "gP", "<Plug>(YankyGPutBefore)", {})

vim.api.nvim_set_keymap("n", "<c-n>", "<Plug>(YankyCycleForward)", {})
vim.api.nvim_set_keymap("n", "<c-p>", "<Plug>(YankyCycleBackward)", {})

require("telescope").load_extension("yank_history")

Feature request: auto format on paste

One of the vim-easyclip's useful features is to automatically format text immediately after paste. It's very useful, but not usable with yanky.

It is slightly different than PutIndent* because the pasted lines do not necessarily have the same indentation as the current line. They can have an extra indent depending on the context.

For example, if the text let a = 1 is pasted when the cursor is on the second line in this example:

function f(flag) {
    if (flag === true) { // <= cursor is on this line
    }
}

the expected result would be:

function f() {
    if (flag === true) {
        let a = 1
    }
}

with YankyPutIndentAfter, we get this:

function f() {
    if (flag === true) {
    let a = 1
    }
}

Note: the request is not to change the behavior of YankyPutIndent* but to add a new option to auto format pasted lines.

try binding <C-k> to move_selection_previous when in Telescope

When I use yanky as a extension of telessope, I find a keymapping conflict that is bound to telescope.actions.move_selection_previous and also to yanky.telescope.mapping.put("p") as default. When I hit , the selected item just being pasted, which is not I expect. I want to know if there a solution for this keymap conflict, Thanks.

Here is my telescope config:

local status_ok, telescope = pcall(require, "telescope")
if not status_ok then
  return
end

telescope.load_extension "file_browser"
telescope.load_extension "yank_history"

local actions = require "telescope.actions"

telescope.setup {
  defaults = {

    prompt_prefix = "  ",
    selection_caret = "  ",
    path_display = { "smart" },

    color_devicons = true,
    scroll_strategy = 'cycle',
    sorting_strategy = 'ascending',
    -- file_ignore_patterns = ignore_these,
    layout_strategy = 'flex',
    layout_config = {
      prompt_position = 'bottom',
      horizontal = {
        mirror = false,
        preview_cutoff = 80,
        preview_width = 0.5,
      },
      vertical = {
        mirror = true,
        preview_cutoff = 0.4,
      },
      flex = {
        flip_columns = 110,
      },
      height = 0.94,
      width = 0.86,
    },

    mappings = {
      i = {
        ["<C-n>"] = actions.cycle_history_next,
        ["<C-p>"] = actions.cycle_history_prev,

        ["<C-j>"] = actions.move_selection_next,
        ["<C-k>"] = actions.move_selection_previous,

        ["<C-c>"] = actions.close,

        ["<Down>"] = actions.move_selection_next,
        ["<Up>"] = actions.move_selection_previous,

        ["<CR>"] = actions.select_default,
        ["<C-x>"] = actions.select_horizontal,
        ["<C-v>"] = actions.select_vertical,
        ["<C-t>"] = actions.select_tab,

        ["<C-u>"] = actions.preview_scrolling_up,
        ["<C-d>"] = actions.preview_scrolling_down,

        ["<PageUp>"] = actions.results_scrolling_up,
        ["<PageDown>"] = actions.results_scrolling_down,

        ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
        ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
        ["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
        ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
        ["<C-l>"] = actions.complete_tag,
        ["<C-/>"] = actions.which_key, -- keys from pressing <C-/>
      },

      n = {
        ["<esc>"] = actions.close,
        ["<CR>"] = actions.select_default,
        ["<C-x>"] = actions.select_horizontal,
        ["<C-v>"] = actions.select_vertical,
        ["<C-t>"] = actions.select_tab,

        ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
        ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
        ["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
        ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist,

        ["j"] = actions.move_selection_next,
        ["k"] = actions.move_selection_previous,
        ["H"] = actions.move_to_top,
        ["M"] = actions.move_to_middle,
        ["L"] = actions.move_to_bottom,

        ["<Down>"] = actions.move_selection_next,
        ["<Up>"] = actions.move_selection_previous,
        ["gg"] = actions.move_to_top,
        ["G"] = actions.move_to_bottom,

        ["<C-u>"] = actions.preview_scrolling_up,
        ["<C-d>"] = actions.preview_scrolling_down,

        ["<PageUp>"] = actions.results_scrolling_up,
        ["<PageDown>"] = actions.results_scrolling_down,

        ["?"] = actions.which_key,
      },
    },
  },
  -- pickers = {
    -- Default configuration for builtin pickers goes here:
    -- picker_name = {
    --   picker_config_key = value,
    --   ...
    -- }
    -- Now the picker_config_key will be applied every time you call this
    -- builtin picker
  -- },
  extensions = {
    file_browser = {
      theme = "ivy",
      -- disables netrw and use telescope-file-browser in its place
      hijack_netrw = true,
      mappings = {
        ["i"] = {
          -- your custom insert mode mappings
        },
        ["n"] = {
          -- your custom normal mode mappings
        },
      },
    },
    -- Your extension configuration goes here:
    -- extension_name = {
    --   extension_config_key = value,
    -- }
    -- please take a look at the readme of the extension you want to configure
  },
}

and here is my yanky config:

local status_ok, yanky = pcall(require, "yanky")
if not status_ok then
  return
end

local actions = require "telescope.actions"
local mapping = require "yanky.telescope.mapping"

yanky.setup {
  ring = {
    history_length = 10,
    storage = "shada",
    sync_with_numbered_registers = true,
  },
  picker = {
    select = {
      action = {
      }, -- nil to use default put action
    },
    telescope = {
      mappings = {
        default = mapping.put("p"),
        i = {
          ["<C-j>"] = actions.move_selection_next,
          ["<C-k>"] = actions.move_selection_previous,
        }
      }
    },
  },
  system_clipboard = {
    sync_with_ring = true,
  },
  highlight = {
    on_put = true,
    on_yank = true,
    timer = 500,
  },
  preserve_cursor_position = {
    enabled = true,
  },
}

Yanky with sqlite enabled in combination with Noice locks up Neovim

Hi!

First of all I really love what you did with Yanky. Awesome plugin!

I enabled the new sqlite storage earlier today and started having lock ups of Neovim pretty consistent.

The lockup itself is caused by some sort of notifying -> triggers error -> tries to notify the error loop.

That part I can fix on my end, but the reason seems to be this error:

E565: Not allowed to change text or change window

I get the lock ups when yanking or deleting lines. About 80% of the time.

It seems the usage of sqlite is causing this somehow. Any ideas?

Confused by `Filter` behavior

Hi, I would like to setup yanky.nvim as follows:

local map = vim.keymap.set

map({"n", "x"}, "y", "<Plug>(YankyYank)")

map({"n", "x"}, "P", "<Plug>(YankyPutBefore)")
map({"n", "x"}, "gP", "<Plug>(YankyGPutBefore)")
map({"n", "x"}, "=P", "<Plug>(YankyPutBeforeFilter)")
map({"n", "x"}, "=gP", "<Plug>(YankyGPutBeforeFilter)")

map({"n", "x"}, "p", "<Plug>(YankyPutAfter)")
map({"n", "x"}, "gp", "<Plug>(YankyGPutAfter)")
map({"n", "x"}, "=p", "<Plug>(YankyPutAfterFilter)")
map({"n", "x"}, "=gp", "<Plug>(YankyGPutAfterFilter)")

map("n", "<A-n>", "<Plug>(YankyCycleForward)")
map("n", "<A-p>", "<Plug>(YankyCycleBackward)")

That is, standard p, P and gP work as usual, the = versions should also indent when pasted and are intended to be used linewise only and for programming.

With this code

void test() {
    int a = 1;
    int b = 2;
    for (int i = 0; i < 10; ++i) {
        cout << a;
        cout << b;
    }
}

copying the two cout lines linewise, positioning the cursor on the line with for, I get

for P:

void test() {
    int a = 1;
    int b = 2;
        cout << a;
        cout << b;
    for (int i = 0; i < 10; ++i) {
        cout << a;
        cout << b;
    }
}

with cursor on first cout

for gP:

void test() {
    int a = 1;
    int b = 2;
        cout << a;
        cout << b;
    for (int i = 0; i < 10; ++i) {
        cout << a;
        cout << b;
    }
}

with cursor before at the beginning of the for line.

for =P

void test() {
    int a = 1;
    int b = 2;
    cout << a;
    cout << b;
    for (int i = 0; i < 10; ++i) {
        cout << a;
        cout << b;
    }
}

with cursor on the first cout.

I would expect =gP to give me a combination of gP and =P, but I get this:

void test() {
    int a = 1;
    int b = 2;
        cout << a;
    cout << b;
    for (int i = 0; i < 10; ++i) {
        cout << a;
        cout << b;
    }
}

which is neither indented correctly, and the cursor is on the cout << b; line, instead of on the for line as in the gP case.

The same behavior occurs for p. When I copy the two int definition lines, position the cursor on the for line, and perform =gp, I get

void test() {
    int a = 1;
    int b = 2;
    for (int i = 0; i < 10; ++i) {
    int a = 1;
        int b = 2;
        cout << a;
        cout << b;
    }
}

with cursor on the pasted int b = 2; instead of one more line below.

I'm using the treesitter indentation, but I tested all wrongly indented examples and =ip indents everything correctly, so = should work properly.

Thank you!

Ability to do character-, line-, or block-wise paste

Hi

Thanks for yanky.

“I occasionally do a linewise yank, and then want to insert that yanked text in the middle of some other line (or vice versa).”

I use the UnconditionalPaste plugin for this and would like to use some of it’s functionality from yanky.

I can’t see how but perhaps it’s possible to use now with config changes ?

Would you see this as integration or would you consider adding the ability to have options do the character-, line-, or block-wise paste ?

Cheers

Don't include plenery.nvim as a git submodule

Hi,
I've noticed this plugin as well as the other two of yours that I'm using (stay-in-place.nvim, substitue.nvim) have plenery.nvim as a git submodule. The plugin folders are 13MiB each on my computer.
It would be much better to handle it as other plugins do - to instead specify plenery.nvim as a dependency in the README and in the suggested plugin spec.

`YankyGPutBefore` and `YankyGPutAfter` swapped?

I found out that to achieve the same behavior as in native nvim, I have to set up like this

local map = vim.keymap.set
map({"n", "x"}, "p", "<Plug>(YankyPutAfter)")
map({"n", "x"}, "P", "<Plug>(YankyPutBefore)")
map({"n", "x"}, "gp", "<Plug>(YankyGPutBefore)")
map({"n", "x"}, "gP", "<Plug>(YankyGPutAfter)")

effectively switching the meanings of gp and gP. Then pasting works like in nvim -u NONE.

Is this a bug or feature?

[Bug] `:YankyRingHistory` puts in last yanked position, instead of cursor

Executing :YankyRingHistory will put the selected text on the last position you yanked from, substituting the last text yanked.

My current config:

use{
	'gbprod/yanky.nvim',
	config = function()
		require("yanky").setup({
			picker = {
				select = {
					action = require("yanky.picker").actions.put("p"),
				},
				telescope = {
					mappings = nil, -- nil to use default mappings
				},
			},
		})
	end
}

Calling YankyRingHistory after yanking a line with newline characters throws error

As mentioned in the subject line, when I call YankRingHistory command after selecting the whole line(including newline char) throws following error
image

However if the line does not have a new line character, this issue is not seen.

My lua config:

	use({
		"stevearc/dressing.nvim",
		after = { "yanky.nvim" },
		disable = false,
		event = "BufEnter",
		config = function() require("dressing").setup() end
	})
	use({
		"gbprod/yanky.nvim",
		disable = false,
		event = "BufEnter",
		-- after = "dressing",
		config = function()
			require("yanky").setup({
				highlight = {
					on_put = true,
					on_yank = true,
					timer = 200,
				},
				preserve_cursor_position = {
					enabled = true,
				},
			})
			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)", {})
		end
	})

'Y' does not copy whole line

'yy' works properly - copy whole line.
The command 'Y' is synonym of 'yy', but it copies line from cursor to end of line.

How to prevent yank on paste?

The keymap:

  vim.keymap.set({ "n", "x" }, "y", "<Plug>(YankyYank)")
  -- TODO: do not yank on paste
  vim.keymap.set({ "n", "x" }, "p", '<Plug>(YankyPutAfter)')
  vim.keymap.set({ "n", "x" }, "P", "<Plug>(YankyPutBefore)")
  vim.keymap.set({ "n", "x" }, "gp", "<Plug>(YankyGPutAfter)")
  vim.keymap.set({ "n", "x" }, "gP", "<Plug>(YankyGPutBefore)")

Race condition?

Given a config like the following packer config:

(use {1 "gbprod/yanky.nvim"
      :config #(let [yanky (require :yanky)]
                  (yanky.setup))})

(use {1 "telescope-nvim/telescope.nvim"
      :requires ["gbprod/yanky.nvim"]
      :config #(let [ts (require :telescope)]
                  (ts.setup {})
                 
                  (ts.load_extension "yank_history"))})

Expected

I would expect that yanky initializes before telescope does given that yanky is a dependency of telescope.

Actual

It seems like a race condition for which :config function runs first. Some loads it's fine, other times I get an error about yank_history not existing at the time the load_extension call fires.

It's possible I'm just being a super noob here and using the wrong packer API here but based on the docs that seems like how it should work?

Please let me know if the fennel is too unfamiliar, I can convert it back to lua if needed.

[BUG] `[p` and `]p` history items get inserted character-wise

The expected behavior for [p and ]p would be that every item is forced line-wise, but any character-wise yanks beyond the first item get inserted character-wise.

Animation

Steps to reproduce:

  1. Yank a character-wise string
  2. [p
  3. Cycle through put history with <C-p>
  4. Observe that character-wise history items show up on the current line

Highlight on yank now in neovim

Nvim now natively provides vim.highlight.on_yank(), which seems to have identical outcome as highlight.on_yank. Perhaps I would consider setting highlight.on_yank off by default so that it doesn't clash out of the box with config of others.

What do you think?

Does not work correctly with Expression register "=

Suppose I need to insert time into text, I can do (<c-M> means ctrl-M)
"=strftime('%c')<C-M>p
In normal mode
With yanky.nvim default mapping of p , it does not insert "= register to current text. I have to nunmap p and "=strftime('%c')<C-M>p it will work.

Error: attempt to index field 'config' (a nil value)

Hello, thanks for the plugin !

I have an error when trying to use yanky to paste (using p).

E5108: Error executing lua: ...ite/pack/packer/start/yanky.nvim/lua/yanky/highlight.lua:36: attempt to index field 'config' (a nil value)
stack traceback:
        ...ite/pack/packer/start/yanky.nvim/lua/yanky/highlight.lua:36: in function 'highlight_put'
        ...are/nvim/site/pack/packer/start/yanky.nvim/lua/yanky.lua:77: in function 'callback'
        ...are/nvim/site/pack/packer/start/yanky.nvim/lua/yanky.lua:141: in function 'init_ring'
        ...are/nvim/site/pack/packer/start/yanky.nvim/lua/yanky.lua:90: in function 'put'
        ...are/nvim/site/pack/packer/start/yanky.nvim/lua/yanky.lua:267: in function <...are/nvim/site/pack/packer/start/yanky.nvim/lua/yanky.lua:266>

I have NVIM v0.9.0-dev. I tried on a remote machine with NVIM v0.8.0 and I have the same problem.

I put in my init.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
  })

and

vim.keymap.set({"n","x"}, "p", "<Plug>(YankyPutAfter)")
vim.keymap.set({"n","x"}, "P", "<Plug>(YankyPutBefore)")
vim.keymap.set({"n","x"}, "gp", "<Plug>(YankyGPutAfter)")
vim.keymap.set({"n","x"}, "gP", "<Plug>(YankyGPutBefore)")

Any idea what could be causing this ?

YankyPutAfterCharacterwiseJoined inserts text twice

Miminal example, save the folliwing in putcharwise.vim

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'gbprod/yanky.nvim'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
require('yanky').setup()
vim.keymap.set('n', 'cp', '<Plug>(YankyPutAfterCharwiseJoined)')
vim.keymap.set('n', 'cP', '<Plug>(YankyPutAfterCharwise)')
EOF

Runnvim --clean -u putcharwise.vim.
Open a new buffer, type ilol<Esc>yiwo<Esc>cp
and lol is inserted twice.
The content of the register seems correct, and cP works correctly, too, so the problem seems to be in the 'Joined' implementation.

Quick grepping indicates this might be the significant code:

function wrappers.trim_and_join_lines(next)
  return function(state, callback)
    local body = vim.fn.getreg(state.register)

    local reformated_body = body:gsub("%s*\r?\n%s*", " "):gsub("^%s*", ""):gsub("%s*$", "")
    vim.fn.setreg(state.register, reformated_body, vim.fn.getregtype(state.register))

    if nil == next then
      callback(state)
    else
      next(state, callback)
    end

    callback(state)
    vim.fn.setreg(state.register, body, vim.fn.getregtype(state.register))
  end
end

My suspicion is that calling callback(state) twice is the problem, is that possible?
Looks like this broke in
#74

Is there any way to determine if it is in Cycle?

I would like to run Cycle only right after <Plug>(YankyPutAfter).
For example, in yankround.vim, I can use yankround#is_active() to fall back to another map if not immediately after put.
https://github.com/LeafCage/yankround.vim

nnoremap <Plug>(ctrl-p) <Nop>
nmap     <C-p>          <Plug>(ctrl-p)
nnoremap <Plug>(ctrl-n) <Nop>
nmap     <C-n>          <Plug>(ctrl-n)

nmap <expr> <C-p> yankround#is_active() ? '<Plug>(yankround-prev)' : '<Plug>(ctrl-p)'
nmap <expr> <C-n> yankround#is_active() ? '<Plug>(yankround-next)' : '<Plug>(ctrl-n)'

nnoremap <Plug>(ctrl-n) <Cmd>OtherPluginMap1<CR>
nnoremap <Plug>(ctrl-p) <Cmd>OtherPluginMap2<CR>

attempt to get length of fi eld 'YANKY_HISTORY' (a nil value)

E5108: Error executing lua ...e/pack/packer/opt/yanky.nvim/lua/yanky/storage/shada.lua:23: attempt to get length of fi
eld 'YANKY_HISTORY' (a nil value)                                                                                     
stack traceback:                                                                                                      
        ...e/pack/packer/opt/yanky.nvim/lua/yanky/storage/shada.lua:23: in function 'length'                          
        ...im/site/pack/packer/opt/yanky.nvim/lua/yanky/history.lua:38: in function 'first'                           
        ...share/nvim/site/pack/packer/opt/yanky.nvim/lua/yanky.lua:87: in function 'put'                             
        [string ":lua"]:1: in main chunk

setup

    keys = {
        "<C-v>",
        "<Plug>(YankyPutAfter)",
        "<Plug>(YankyPutBefore)",
        "<Plug>(YankyPutAfter)",
        "<Plug>(YankyPutBefore)",

        "<Plug>(YankyGPutAfter)",
        "<Plug>(YankyGPutBefore)",
        "<Plug>(YankyGPutAfter)",
        "<Plug>(YankyGPutBefore)",

        "<Plug>(YankyCycleForward)",
        "<Plug>(YankyCycleBackward)",
    },
    setup = function()
        local default_keymaps = {
            { "n", "p", "<Plug>(YankyPutAfter)" },
            { "n", "P", "<Plug>(YankyPutBefore)" },

            { "x", "p", "<Plug>(YankyPutAfter)" },
            { "x", "P", "<Plug>(YankyPutBefore)" },

            { "n", "<leader>p", "<Plug>(YankyGPutAfter)" },
            { "n", "<leader>P", "<Plug>(YankyGPutBefore)" },

            { "x", "<leader>p", "<Plug>(YankyGPutAfter)" },
            { "x", "<leader>P", "<Plug>(YankyGPutBefore)" },

            { "n", "<Leader>n", "<Plug>(YankyCycleForward)" },
            { "n", "<Leader>N", "<Plug>(YankyCycleBackward)" },
        }
        for _, m in ipairs(default_keymaps) do
            vim.keymap.set(m[1], m[2], m[3], {})
        end
    end,
    config = function()
        require("yanky").setup({
            ring = {
                history_length = 10,
                storage = "shada",
            },
        })
    end,

`vim.highlight.link` is deprecated

After updating neovim to its latest nightly, getting this warning

vim.highlight.link is deprecated, use vim.api.nvim_set_hl instead. See :h deprecated
This function will be removed in Nvim version 0.9

Are we going to do something for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.