David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
992 stars 64 forks source link

Which-key seems to "steal" the buffer content #16

Closed kozer closed 7 months ago

kozer commented 9 months ago

I'm using lazyvim, and I have added a keybinding for gen.nvim. It seems that because which-key is triggered, the content of the buffer is empty and so the $text parameter. ( In visual mode ). If I use : to trigger the Gen command, it seems it works as expected.

David-Kunz commented 9 months ago

Hi @kozer ,

Thanks for reporting. I'm not using which-key, do you know how to fix this?

Thank you and best regards, David

kozer commented 9 months ago

No unfortunately. I tried ( but not put much effort into it). ). I'm willing to try to fix it, but can you guide me through debugging? How can I try my changes without pushing?

desilinguist commented 9 months ago

I am also having the same issue with whichkey. :Gen works as expected.

David-Kunz commented 8 months ago

Hi @kozer ,

Thank you! If you're using lazyvim, you can set it to dev: true:

    {'David-Kunz/gen.nvim', dev = true},

clone the repository and set the path

require('lazy').setup({...}, {dev = {path = "<your_path_to_parent_folder_of_repo>"}})
kozer commented 8 months ago

Thank you @David-Kunz ! I'll try to work on it asap ! Thanks for the info you provided! They are very useful!

bjosttveit commented 8 months ago

I am also using Lazy and have which-key installed. I experienced the exact same issue when I had defined the key bindings in keys inside the plugin config. I solved the issue by setting the keymaps outside of the plugin config using the regular vim.keymap.set method instead. So I don't think which-key is necessarily the problem here.

nomnivore commented 8 months ago

If I'm not mistaken, this has something to do with how ":" and "" keybindings work with visual mode & its marks.

Try using something like this for the rhs of your keybind: :<c-u>Gen<cr>

pratikgajjar commented 8 months ago

I am also using Lazy with which-key enabled, haven't faced any issue

vitorf7 commented 8 months ago

The problem seems to arise when using either "" (nothing and therefore assuming an Editor command) or "" in which key.

Take the following lazy.nvim configuration:

return {
  "David-Kunz/gen.nvim",
  keys = {
    { "<leader>ga", ":Gen<CR>", desc = "Ollama Generate", mode = { "n", "v" } }, -- This Works
    -- { "<leader>ga", "<cmd>Gen<CR>", desc = "Ollama Generate", mode = { "n", "v" } }, -- This does NOT Work
    -- { "<leader>ga", "Gen<CR>", desc = "Ollama Generate", mode = { "n", "v" } }, -- This does NOT Work
  },
  config = function(_, _)
    -- vim.keymap.set("n", "<leader>ga", ":Gen<CR>", { silent = true }) -- This Works
    -- vim.keymap.set("v", "<leader>ga", ":Gen<CR>", { silent = true }) -- This Works
    require("gen").model = "llama2"
  end,
}
David-Kunz commented 7 months ago

Hi @kozer ,

Is this issue solved?

RingOfStorms commented 7 months ago

Hi @kozer ,

Is this issue solved?

I also had this issue. Based on @vitorf7 's answer I switched all of my <cmd> to : and it all works fine now for me.

David-Kunz commented 7 months ago

Thanks for the confirmation, @RingOfStorms !