huggingface / llm.nvim

LLM powered development for Neovim
Apache License 2.0
727 stars 45 forks source link

expose callbacks #66

Open teto opened 10 months ago

teto commented 10 months ago

as I started my neovim, I got surprised that my <tab> key was doing non-sense. As I had just installed llm.nvim the culprit was evident (plus :verb map <tab>). Tab is an important key so I dont think the plugin should hijack it like this. I would prefer for the plugins to expose its callbacks and let me map them. The mapping could be kept in the README out of the setup function. The setup function meme can be quite annoying when you compose your setup https://mrcjkb.dev/posts/2023-08-22-setup.html

McPatate commented 10 months ago

Do you have any examples of plugins that do it "the right way"?

Also, is this linked to #61?

teto commented 10 months ago

Historically, plugins expose their mappings via <Plug>Name. In lua that would give:

vim.keymap.set("n", "<Plug>HelloWorld", function() print("Hello World!") end)
vim.keymap.set("n", "gs", "<Plug>HelloWorld")

in the readme, you could remove the mappings from the setup() but still document them in the snippet:

require("lazy").setup({
  {
    'huggingface/llm.nvim',
    config = function() require'llm'.setup {
      -- cf Setup
      opts
    }
    vim.keymap.set("n", "gs", "<Plug>LlmAcceptSuggestion")
    end
  },
})
teto commented 10 months ago

but with lua I am not sure you need to go through the Plug route anyway, you could straightaway document: vim.keymap.set("n", "gs", function () require'llm'.accept_suggestion() end)

jodosha commented 2 months ago

+1

My specific use case is to provide more context to the prompt in order to get more accurate results.