Open benwoodward opened 1 year ago
I am also troubled by this, let’s find a solution together.
I am also troubled by this to long.
Also troubled in :
Oh, I fix it.., by add an option to completion = { completeopt = 'menu,menuone,noselect' }
to cmd.setup.cmdline()
.
-- `/` cmdline setup.
cmp.setup.cmdline({ '/', '?' }, {
completion = { completeopt = 'menu,menuone,noselect' },
sources = {
{ name = 'buffer' },
},
})
-- `:` cmdline setup.
cmp.setup.cmdline(':', {
completion = { completeopt = 'menu,menuone,noselect' },
sources = cmp.config.sources(
{ { name = 'path' } },
{ { name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } } }
),
})
But I can't understand, I have added this option to cmd.setup
. Why not used in cmd.cmdline:
cmp.setup({
completion = {
completeopt = 'menu,menuone,noinsert',
},
...
})
Using <C-y>
to confirm the selection.
The default keybindings:
mapping.preset.cmdline = function(override)
return merge_keymaps(override or {}, {
-- omitted code
['<C-e>'] = {
c = mapping.abort(),
},
['<C-y>'] = {
c = mapping.confirm({ select = false }),
},
})
end
You can override the default key by adding an argument to cmp.mapping.preset.cmdline
:
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline({
["<cr>"] = {
c = cmp.mapping.confirm({ select = false }),
},
}),
sources = cmp.config.sources({
{ name = "path" },
}, {
{
name = "cmdline",
option = {
ignore_cmds = { "Man", "!" },
},
},
}),
})
In this case, then you can use <cr>
to confirm.
Here's an example, I search for 'comp', first result is 'compare' and is selected, I hit enter and it searches for 'comp'. To select and search 'compare' I need to hit
tab
+shift-tab
+enter
. Would be great if the first option wasn't selected until I tab to it (so I don't need to tab forwards and backwards to actually select it).https://github.com/hrsh7th/cmp-cmdline/assets/1472981/4cd9c732-512d-434c-9328-46967625c959