Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for visual selection override #128

Open
peterfication opened this issue Jun 20, 2024 · 6 comments · May be fixed by #129
Open

Allow for visual selection override #128

peterfication opened this issue Jun 20, 2024 · 6 comments · May be fixed by #129

Comments

@peterfication
Copy link

I often select a certain word and want to replace it with a paste. Unfortunately, I can't use neoclip properly yet when doing this because it says "No visual range allowed".

I could fake it with a visual keymap to d:Telescope neoclip<CR>, which first deletes the selected word and then opens Neoclip. However, if I cancel, the word will be deleted anyways.

Is it somehow possible to add a visual range? Or is it too complex?

@AckslD
Copy link
Owner

AckslD commented Jun 20, 2024

I think it should be possible to add, just hasn't been done :) I'm not sure I'll have time in the near future so if anyone wants to take a stab at this feel free to :)

@peterfication
Copy link
Author

So the first problem is that I used a mapping of :Telescope Telescope neoclip<CR> which results in the problem of "No visual range allowed". If I map <CMD>Telescope neoclip<CR>, it works just fine.

However, the pasted text is inserted before of after the cursor, but it does not overwrite the visual selection. So I will look into the code to see whether this can be adapted in a reasonable amount of effort.

@peterfication
Copy link
Author

According to this comment, it might not be possible in neoclip at all, but needs to be handled outside of neoclip.

The problem is that you loose the visual selection as soon as Telescope opens. So one solution could be to write a function that saves the visual selection somewhere and on select of a neoclip entry select the visual range again.

@peterfication
Copy link
Author

So I made it work with the following:

Visual keymap: <ESC><CMD>Telescope neoclip<CR> (The <ESC> is necessary to "save" the visual selection).

Custom neoclip action:

      local function visual_paste(opts)
        local handlers = require("neoclip.handlers")
        handlers.set_registers({ 'z' }, opts.entry)
        vim.api.nvim_feedkeys('gv"zp', "n", false)
      end

      require("neoclip").setup({
        -- ...
        keys = {
          telescope = {
            n = {
              custom = {
                ["v"] = visual_paste
              },
            },
            i = {
              custom = {
                ["<c-v>"] = visual_paste
              },
            },
          },
        },
      })

@AckslD Should I contribute this to the README?

@AckslD
Copy link
Owner

AckslD commented Jul 9, 2024

Nice @peterfication! I think it would be great to support this natively, would you like to add an PR for that? Otherwise I can give it a shot when I find the time. Let me know :)

peterfication added a commit to peterfication/nvim-neoclip.lua that referenced this issue Jul 11, 2024
@peterfication peterfication linked a pull request Jul 11, 2024 that will close this issue
@peterfication
Copy link
Author

I gave it a try :)

=> Let's continue the discussion there.

peterfication added a commit to peterfication/nvim-neoclip.lua that referenced this issue Jul 11, 2024
peterfication added a commit to peterfication/nvim-neoclip.lua that referenced this issue Jul 11, 2024
peterfication added a commit to peterfication/nvim-neoclip.lua that referenced this issue Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants