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

feat(cmdline): allow configuring separate cmdline preset #532

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

folke
Copy link
Contributor

@folke folke commented Dec 13, 2024

This PR does two things:

  • allow configuring a different keymap for the cmdline
  • added a default preset more closely matching the default Neovim cmdline keymaps

Closes #514

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

Thinking about this more, specifically for the cmdline, users will probably want to customize other config options as well.
Like auto_insert etc, so maybe a better approach (but way more code changes) would be to allow a complete different config for the cmdline.

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

This PR is indeed not enough.
Personally I'd want to have auto_insert enabled, but with no preselect and use <tab> / <S-Tab> to cycle between results.

Not sure what the best approach is. I've disabled the cmdline integration for now in LazyVim.

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

so maybe a better approach (but way more code changes) would be to allow a complete different config for the cmdline.

That would make the entire config dynamic which would make this much more complicated. I'd like to avoid this if possible

Personally I'd want to have auto_insert enabled, but with no preselect and use <tab> / <S-Tab> to cycle between results.

So you'd like auto_insert in default mode and preselect in cmdline mode just to clarify? If that's the only change, maybe we can have a select few options as dynamic

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

I think so? :)
I don't have anything configured regarding preselect and auto_insert right now for blink.

I want to achieve a similar setup as with the regular cmdline, as in:

When I type T, the menu opens like this:
image

<tab> then cycles forward (<s-tab> backwards) and inserts the items when doing so, so you can press <cr> anytime to exeucte

image
image

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

These are the options I set:

vim.opt.completeopt = "menu,menuone,noselect"

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

The screenshots are Noice obviously, but that behaves exactly as the normal cmdline regarding completion.

@the-fuckin-nobody
Copy link

So you'd like auto_insert in default mode and preselect in cmdline mode just to clarify?

Maybe make blink.cmp.select_next() take an extra argument of type same as blink.cmp.config.completion.list.selection ?

So we can set keymaps like this:

['<Tab>'] = {
function(cmp)
    if vim.fn.getcmdtype() == '' then
        return cmp.select_next({select_behaviour = 'preselect'})
    end
    return cmp.select() -- selection_behaviour defaults to `auto_insert`
end }

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

@the-fuckin-nobody though about doing it that way initially, but in my case, the first entry would already be pre-selected, so you can't use <tab> to next&insert then.

@the-fuckin-nobody
Copy link

@the-fuckin-nobody though about doing it that way initially, but in my case, the first entry would already be pre-selected, so you can't use <tab> to next&insert then.

If I am understanding it correctly, is this the desired behaviour?

recording.mp4

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

Yep, exactly.

@the-fuckin-nobody
Copy link

the-fuckin-nobody commented Dec 13, 2024

Yep, exactly.

Then, it is actually doable with the current state of the plugin, by configuring the tab keymap like this like this and having the selection behaviour as auto_insert:

["<Tab>"] = {
				function(cmp)
					if vim.fn.getcmdtype() ~= "" then
						return cmp.select_next()
					elseif cmp.snippet_active() then
						return cmp.accept()
					end
				end,
				"snippet_forward",
				"fallback",
			},

But in my case I would prefer to have selection behaviour as preselct for normal completion menu and auto_insert for cmdline completion menu.

@folke
Copy link
Contributor Author

folke commented Dec 13, 2024

But in my case I would prefer to have selection behaviour as preselct for normal completion menu and auto_insert for cmdline completion menu.

Yep same here

@the-fuckin-nobody
Copy link

Yep same here

image
I just found this line while skimming through the codebase , but skip_auto_insert has not been implemented yet. Implementing this may achieve the purpose

@Saghen Saghen merged commit 13b3e57 into Saghen:main Dec 13, 2024
@Parsifa1
Copy link
Contributor

any progress about handling the 'special' auto_insert for cmdline?

@the-fuckin-nobody
Copy link

any progress about handling the 'special' auto_insert for cmdline?

That should be done in another PR I guess cuz its unrelated to this PR(cmdline keymaps).

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

Yep, I'm still working out how I want to solve it

@the-fuckin-nobody
Copy link

Yep, I'm still working out how I want to solve it

Take a break bro not everything must be implemented right away!

PS: You're awesome

@Parsifa1
Copy link
Contributor

any progress about handling the 'special' auto_insert for cmdline?

for those who find here and want some temp fix:
here is a snippet💖:
(remember to set <CR> to {} )

init = function()
        -- FIX: Temporary for not being able to set auto_insert for cmdline
        local orig_list_selection = nil
        vim.api.nvim_create_autocmd("CmdlineEnter", {
            callback = function()
                local list = require "blink.cmp.completion.list"
                orig_list_selection = list.config.selection
                list.config.selection = "auto_insert"
            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,
        })
    end,

ref https://github.com/Parsifa1/nvim/blob/4ce2ab13d428f3efa6ae269bff030f033f59dceb/lua/plugins/lsp/blink.lua

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

Successfully merging this pull request may close these issues.

Add separate keymap settings for cmdline completions.
4 participants