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

Expose nvim-cmp preselect option #670

Open
1 task done
picogeyer opened this issue Feb 27, 2025 · 3 comments
Open
1 task done

Expose nvim-cmp preselect option #670

picogeyer opened this issue Feb 27, 2025 · 3 comments

Comments

@picogeyer
Copy link

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find a similar feature request

🏷️ Feature Type

API Additions

🔖 Feature description

I've been trying to use NeoVim with autocomplete but the behavior I have always preferred is to not autoselect a completion until the tab key is pressed. That way if I type something quickly that ends in Enter, it does not insert a completion.

My old config had lsp-zero (which seems deprecated)

local lsp = require('lsp-zero')
...
lsp.setup_nvim_cmp({
  preselect = 'none',
  completion = {
    completeopt = 'menu,menuone,noinsert,noselect'
  },
})

I believe the correct way to do this without lsp-zero is

local cmp = require'cmp'
cmp.setup{
  ...
  preselect = cmp.PreselectMode.None
}

I found this here: https://www.devonmorris.dev/posts/nvim-cmp-preselect/

I tried the following with NVF:

    settings = {
      vim = {
        autocomplete.nvim-cmp = {
          enable = true;
          setupOpts = {
            completion.completeopt = "menu,menuone,noinsert,noselect";
            preselect = "none";
          };
        };

Somehow this still doesn't work. The completion menu is visible but no item is selected, pressing enter selects the first item instead of inserting a newline.
Somehow the preselect option is not taking effect.
Am I doing something wrong?
Could this just be exposed via NVF to make this a little easier?

✔️ Solution

I would like an option to configure the preslect behaviour of nvim-cmp

❓ Alternatives

If this can be done without exposing a nix option, I'd be happy with that solution too.

📝 Additional Context

No response

@NotAShelf
Copy link
Owner

NotAShelf commented Feb 27, 2025

setupOpts is a special submodule that converts everything passed to Lua as much as it can. String literals, as they are string literals, get converted to Lua strings- which is actually not the same as Lua functions.

Use lib.generators.mkLuaInline for anything that you need interpreted as "raw" Lua. For example, preselect = lib.generators.mkLuaInline "cmp.PreselectMode.None";

I understand that this is a little confusing, I'll add a type-checked option for future reference when I get back to my system.

@picogeyer
Copy link
Author

@NotAShelf That is useful info, I was wondering how that was done.

I think "none" should have worked as well because cmp.PreselectMode.None seems to evaluate to "none" when I print it out with
:lua cmp = require("cmp"); vim.print(cmp.PreselectMode.None)

However, neither seems to work correctly.
I can try debug this on my own, do you have any suggestions for debugging?
I tried to copy the generated config to a temporary dir and then make modifications to it, then run it with vim -u /path/to/new/config.lua but I get other errors about the plugin paths.

@NotAShelf
Copy link
Owner

If there aren't any errors, then my guess would be on a configuration option conflict. Starting neovim with the init.lua in the store won't work because plugins are missing in the environment. Your best bet would be isolating nvim-cmp configuration, and creating a minimal standalone nvf environment to mess with nvim-cmp only.

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

2 participants