AckslD / nvim-neoclip.lua

Clipboard manager neovim plugin with telescope integration
944 stars 20 forks source link

[Feature request] operator filter #47

Closed rockyzhang24 closed 2 years ago

rockyzhang24 commented 2 years ago

Sometimes we only care about the contents yanked by parts of the operators. For example, I just want to record all the contents yanked by y, and ignore the contents yanked by d, c, etc. Is it possible to have a variable in the config to maintain the operator list like operator_filter = { 'y' }.

Thank you very much.

AckslD commented 2 years ago

You should already be able to do this with the current filter, for example by

require('neoclip').setup({
  ...
  filter = function(data)
    return data.event.operator == 'y' 
  end, 
  ...
})
rockyzhang24 commented 2 years ago

I was testing this after I opened this issue. Lol. Thank you very much.

lukoshkin commented 2 years ago

Is there a way to filter out 'x' presses and keep yanked text with 'd'? Since 'x' presses fall under 'd' category according to print(data.event.operator)

lukoshkin commented 2 years ago

Ok, I solved the history of yanks cluttering problem by introducing this filter:

  filter = function (_)
    return vim.fn.strlen(vim.fn.getreg('"')) > vim.g.neoclip_min_length
  end,

(NOTE: vim.g.neoclip_min_length must be defined) One can also strip the unnamed register content of whitespace chars, but for now, I decided to stick with this version

AckslD commented 2 years ago

Nice @lukoshkin, you could also get the yanked content from data.event.regcontent where data is passed to the filter (untested, on my phone :))