ibhagwan / smartyank.nvim

137 stars 3 forks source link

Option to not consider deletes clipboard pollution #8

Closed mikepqr closed 1 year ago

mikepqr commented 1 year ago

The docs say:

"Minimum clipboard/register pollution: only copy to clipboard when I intent on doing so (i.e. do not overwrite my clipboard on neovim's dd and similar operations)"

I like all the features except this one! As a longime vim user I am too used to deletes (including dd) going to my vim clipboard. I am fine with them overwriting my system clipboard. They are not pollution for me.

Is there any chance this feature could be a configurable option?

(And would it be possible to document more precisely what "dd and similar operations" mean? And what clipboard = { enabled = true } does.)

ibhagwan commented 1 year ago

Is there any chance this feature could be a configurable option?

You don't need to configure anything, the statement above assumes set clipboard= is unset, if you have set clipboard=unnamedplus (or unnamed) your clipboard polution will continue uninterrupted :-)

And would it be possible to document more precisely what "dd and similar operations" mean? And what clipboard = { enabled = true } does.

When clipboard is enabled and the event TextYankPost is triggered (neovim event, AFAIK vim doesn't have it), the plugin checks that vim.v.operator == y, i.e. that you yanked with a y motion and then copies the contents of the yank register 0 into the clipboard register +.

If you're using set clipboard=... you can safely disable clipboard as you obviously don't need this, your content should be automatically copied into the clipboatd.

mikepqr commented 1 year ago

If you're using set clipboard=... you can safely disable clipboard as you obviously don't need this, your content should be automatically copied into the clipboard.

I don't think it's "obvious" because I'm not sure what "this" is! :-)

Is this correct?

  1. for users who have set clipboard=, and smartyank with clipboard = { enabled = true }
    • yank motions (including on remote hosts) go in the system clipboard (via OSC52) and the tmux clipboard
    • delete motions do not go in the system or tmux clipboard
  1. for users who have set clipboard=unnamedplus, and smartyank clipboard = { enabled = true }:

    • yank motions (including on remote hosts) go in the system clipboard (via OSC52) and the tmux clipboard
    • delete motions go in the system clipboard (but not the tmux clipboard) via the usual nvim approaches (e.g. pbcopy on macOS)
  2. for users who have set clipboard=unnamedplus, and smartyank clipboard = { enabled = false }:

    • yanks and deletes on local hosts go in the system clipboard, but do not go in the tmux clipboard
  3. Right now, smartyank does not have a way to get delete motions on remote hosts to the system clipboard (this is really what my original question is about, and the option I'm looking for!)

  4. if you set clipboard = { enabled = false } the only thing smartyank does is enable yank highlighting

ibhagwan commented 1 year ago

I don't think it's "obvious" because I'm not sure what "this" is! :-)

I apologize, was answring rushed from a mobile device :-)

What I meant was you can safely set clipboard = { enabled = false }

  1. Correct
  2. Correct
  3. Incorrect, the way the plugin works is monitoring the TextYankPost, when an event is triggered it does 3 things (in this order):
    • If clipboard is enabled, copy to the + register (system clipboard)
    • If osc52 is enabled, send OSC52 sequence to the terminal
    • If tmux is enabled, copy to a tmux buffer using tmux set-buffer -w ...
    • if highlight is enabled, highlight the yanked selection using vim.highlight.on_yank
  4. Correct, all the above is conditioned on being an intentional yank using the y operator: https://github.com/ibhagwan/smartyank.nvim/blob/cd191d9629d620ccc608e6b4e60f3541264d0323/lua/smartyank/init.lua#L145
  5. Incorrect, tmux and OSC52 handlers will be still be called as explained in (3)

this is really what my original question is about, and the option I'm looking for!

I'll add an override for this.

ibhagwan commented 1 year ago

https://github.com/ibhagwan/smartyank.nvim/commit/054d69dd9e61a745f58c556ff0a2a91b621c8b0f - update to the latest commit and use:

require("smartyank").setup({ validate_yank=false })
mikepqr commented 1 year ago

lmao "copy indiscriminately" :-)

Thank you very much for the quick and clear response, and for the new feature!

ibhagwan commented 1 year ago

lmao "copy indiscriminately" :-)

consistent with “clipboard pollution” :)