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

cmdline: enter keymap preset issues #542

Open
2 tasks done
b0o opened this issue Dec 13, 2024 · 9 comments
Open
2 tasks done

cmdline: enter keymap preset issues #542

b0o opened this issue Dec 13, 2024 · 9 comments
Labels
bug Something isn't working cmdline Related to the command line keymap

Comments

@b0o
Copy link
Contributor

b0o commented Dec 13, 2024

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

When keymap is set to the enter preset, there are a few issues:

  • command abbreviations (cabbrev) are not expanded before the command is executed (E492: Not an editor command)
    • note: the first completion may be the expanded completion - to repro, don't accept that, dismiss the cmp popup and then try to accept the abbreviated command alone
  • if auto_insert is enabled, when picking a completion item, you need to press enter twice to run the command

Relevant configuration

{
  keymap = { preset = 'enter' },
  completion = {
    list = {
      selection = 'auto_insert',
    },
  },
}

neovim version

NVIM v0.11.0-dev-1273+g7a367c6967

blink.cmp version: branch, tag, or commit

fb03ca7

@b0o b0o added the bug Something isn't working label Dec 13, 2024
@the-fuckin-nobody
Copy link

the-fuckin-nobody commented Dec 13, 2024

The default preset for cmdline completions is now super-tab as mentioned in the README. You may want to add cmdline = { preset = 'enter' }} to your keymap table.

Edit: this is irrelavant pls ignore

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

That's actually just an example, it'll use your keymap.preset by default

@Saghen Saghen added the cmdline Related to the command line label Dec 13, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

if auto_insert is enabled, when picking a completion item, you need to press enter twice to run the command

It's a bit unintuitive but I think this behavior makes sense since it matches the behavior in default mode. Maybe you could unmap enter in cmdline mode to get the behavior you're looking for

keymap = {
  cmdline = {
    preset = 'enter',
    ['<CR>'] = {}
  }
}

@b0o
Copy link
Contributor Author

b0o commented Dec 13, 2024

Thanks, that does work.

Perhaps there can be separate presets for cmdline with intuitive defaults. Then, doing keymap = { preset = 'enter' } would use the cmdline-specific preset for command mode. Though, in this case, I suppose "enter" isn't a great name, because it would exclude that particular keymap from the preset. Hmm..

On second thought, I think the most intuitive solution would be for the cmdline keymap configuration to not be nested inside of the standard keymaps, but to be in e.g. cmdline_keymap or cmdline.keymap. Then, I would expect changing the standard keymaps to not change the cmdline keymaps. This would make it more clear what mappings will be applied where.

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

I think typically if you wanted to run the first option, you would press enter twice (first to accept, second to run). You could make a keymap that selects, accepts and runs

keymap = {
  cmdline = {
    preset = 'enter',
    -- We don't return so that the fallback runs
    ['<CR>'] = { function(cmp) cmp.select_and_accept() end, 'fallback' }
  }
}

On second thought, I think the most intuitive solution would be for the cmdline keymap configuration to not be nested inside of the standard keymaps, but to be in e.g. cmdline_keymap or cmdline.keymap. Then, I would expect changing the standard keymaps to not change the cmdline keymaps. This would make it more clear what mappings will be applied where.

Totally agree! I'm thinking it would make sense to have a cmdline section that includes some of the settings from the main config (i.e. completion.list.selection, keymap, among others) for overriding settings in cmdline mode.

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

command abbreviations (cabbrev) are not expanded before the command is executed (E492: Not an editor command)

This should be fixed on main after 89479f3

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

On the latest commit, you can do something like

['<CR>'] = {
  function(cmp)
    return cmp.select_and_accept({
      callback = function()
        vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<CR>', true, true, true), 'n', true)
      end,
    })
  end,
  'fallback',
}

@Saghen Saghen added the keymap label Dec 13, 2024
@b0o
Copy link
Contributor Author

b0o commented Dec 13, 2024

On the latest commit, you can do something like

Thanks, this works exactly how I want, as long as I set selection = 'manual'

I'm thinking it would make sense to have a cmdline section that includes some of the settings from the main config (i.e. completion.list.selection, keymap, among others) for overriding settings in cmdline mode.

This would be perfect!

@b0o
Copy link
Contributor Author

b0o commented Dec 13, 2024

I'm thinking it would make sense to have a cmdline section that includes some of the settings from the main config (i.e. completion.list.selection, keymap, among others) for overriding settings in cmdline mode.

As a temporary workaround until this is implemented, in order to use completion.list.selection = "auto_insert" in insert mode and "manual" in command mode, I'm using CmdlineEnter/Leave autocommands to manipulate the list selection configuration setting:

local orig_list_selection
vim.api.nvim_create_autocmd('CmdlineEnter', {
  callback = function()
    local list = require 'blink.cmp.completion.list'
    orig_list_selection = list.config.selection
    list.config.selection = 'manual'
  end,
})
vim.api.nvim_create_autocmd('CmdlineLeave', {
  callback = function()
    if orig_list_selection then
      local list = require 'blink.cmp.completion.list'
      list.config.selection = orig_list_selection
    end
  end,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cmdline Related to the command line keymap
Projects
None yet
Development

No branches or pull requests

3 participants