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

Tab key not usable in insert mode #61

Open
bogdan-the-great opened this issue Oct 10, 2023 · 6 comments
Open

Tab key not usable in insert mode #61

bogdan-the-great opened this issue Oct 10, 2023 · 6 comments

Comments

@bogdan-the-great
Copy link

Using this config:

"huggingface/llm.nvim",
event = "VeryLazy",
opts = {
    api_token = "<key>",

    {
        tokens_to_clear = { "<|endoftext|>" },
        fim = {
            enabled = true,
            prefix = "<fim_prefix>",
            middle = "<fim_middle>",
            suffix = "<fim_suffix>",
        },
        model = "codellama/CodeLlama-34b-Instruct-hf",
        context_window = 8192,
        tokenizer = {
            repository = "codellama/CodeLlama-34b-Instruct-hf",
        }
    },

    enable_suggestions_on_startup = false,
    lsp = {
        bin_path = vim.api.nvim_call_function("stdpath", { "data" }) .. "/mason/bin/llm-ls",
    },
},

I am unable to use the Tab key in the insert mode when suggestions are on, but Tab works for accepting outputted code. Changing accepting and dismissing keys only made them not usable (in insert mode), and Tab working again.

@McPatate
Copy link
Member

You want Tab to be bound to multiple things? Are you sure that when you set accept/dismiss keymap they don't work?

I currently have them on Alt+i and it works fine

@bogdan-the-great
Copy link
Author

I mean they work, but only for llm.nvim's actions and not for everything else, e.g. tab only accepts output from LLMs and doesn't insert tab chars.

@McPatate
Copy link
Member

This is how I define the keymaps:

  vim.keymap.set("i", accept_keymap, accept_suggestion, { expr = true })

  vim.keymap.set("n", accept_keymap, accept_suggestion, { expr = true })

  vim.keymap.set("i", dismiss_keymap, dismiss_suggestion, { expr = true })

  vim.keymap.set("n", dismiss_keymap, dismiss_suggestion, { expr = true })

in https://github.com/huggingface/llm.nvim/blob/main/lua/llm/keymaps.lua#L25

I'll check how to make it so that it doesn't override other functionalities, let me know if you know the lua to do that.

@bogdan-the-great
Copy link
Author

So after a little bit of testing I binded accept to Alt-j and dismiss to i (when you start typing it dismisses suggestion anyway). I now see that it should be binded to other key than tab because of completion and snippets. But fixing the issue for example with not working esc or enter would be useful.

@ybkimm
Copy link

ybkimm commented Nov 13, 2023

I think this should work:

ybkimm@83fc599

@williamspatrick
Copy link

This is how I define the keymaps:

  vim.keymap.set("i", accept_keymap, accept_suggestion, { expr = true })

  vim.keymap.set("n", accept_keymap, accept_suggestion, { expr = true })

  vim.keymap.set("i", dismiss_keymap, dismiss_suggestion, { expr = true })

  vim.keymap.set("n", dismiss_keymap, dismiss_suggestion, { expr = true })

in https://github.com/huggingface/llm.nvim/blob/main/lua/llm/keymaps.lua#L25

I'll check how to make it so that it doesn't override other functionalities, let me know if you know the lua to do that.

nvim-cmp has a "fallback" functionality. You can find their code here:

https://github.com/hrsh7th/nvim-cmp/blob/04e0ca376d6abdbfc8b52180f8ea236cbfddf782/lua/cmp/utils/keymap_spec.lua#L37

I use it like this to make it so that <Tab> can be both "select next completion" and a real <Tab>.

https://github.com/williamspatrick/dotfiles/blob/69ebda8b3e9e469c7d3bb5ecaf9fce2da7c66623/vim/plugin/lua/nvim-cmp.lua#L15

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

No branches or pull requests

4 participants