doc/modes/cmdline.md
::: info If you want cmdline's behavior to match the default mode, try the following config:
cmdline = {
keymap = { preset = 'inherit' },
completion = { menu = { auto_show = true } },
},
:::
By default, cmdline completions are enabled (cmdline.enabled = true), matching the behavior of the built-in cmdline completion:
cmdline.completion.menu.auto_show = false)<Tab> will show the completion menu and insert the first item
<Tab>s will select the next item, <S-Tab> for previous item<C-n> for next item, <C-p> for previous item<C-y> accepts the current item<C-e> cancels the completionSee the reference configuration for the complete list of options.
Set via cmdline.keymap.preset = 'cmdline', which is the default. Set to 'none' to disable the preset or 'inherit' to inherit the mappings from the top level keymap. See the keymap documentation for more information on defining your own.
{
-- optionally, inherit the mappings from the top level `keymap`
-- instead of using the neovim defaults
-- preset = 'inherit',
['<Tab>'] = { 'show_and_insert_or_accept_single', 'select_next' },
['<S-Tab>'] = { 'show_and_insert_or_accept_single', 'select_prev' },
['<C-space>'] = { 'show', 'fallback' },
['<C-n>'] = { 'select_next', 'fallback' },
['<C-p>'] = { 'select_prev', 'fallback' },
['<Right>'] = { 'select_next', 'fallback' },
['<Left>'] = { 'select_prev', 'fallback' },
['<C-y>'] = { 'select_and_accept', 'fallback' },
['<C-e>'] = { 'cancel', 'fallback' },
}
When noice.nvim is detected, ghost text will be shown, likely similar to your terminal shell completions. Pressing <Tab> will open the menu and insert the first item as per usual.
cmdline = { completion = { ghost_text = { enabled = true } } }
By default, the completion menu will not be shown automatically. You may set cmdline.completion.menu.auto_show = true to have it appear automatically.
cmdline = {
keymap = {
-- recommended, as the default keymap will only show and select the next item
['<Tab>'] = { 'show', 'accept' },
},
completion = { menu = { auto_show = true } },
}
However, you may want to only show the menu only when writing commands, and not when searching or using other input menus.
cmdline = {
keymap = {
-- recommended, as the default keymap will only show and select the next item
['<Tab>'] = { 'show', 'accept' },
},
completion = {
menu = {
auto_show = function(ctx)
return vim.fn.getcmdtype() == ':'
-- enable for inputs as well, with:
-- or vim.fn.getcmdtype() == '@'
end,
},
}
}
When using <Enter> (<CR>) to accept the current item, you may want to accept the completion item and immediately execute the command. You can achieve this via the accept_and_enter command. However, when writing abbreviations like :wq, with the menu automatically showing, you may end up accidentally accepting a completion item. Thus, you may disable the completions when the keyword, for the first argument, is less than 3 characters.
cmdline = {
keymap = {
['<Tab>'] = { 'accept' },
['<CR>'] = { 'accept_and_enter', 'fallback' },
},
-- (optionally) automatically show the menu
completion = { menu = { auto_show = true } }
},
sources = {
providers = {
cmdline = {
min_keyword_length = function(ctx)
-- when typing a command, only show when the keyword is 3 characters or longer
if ctx.mode == 'cmdline' and string.find(ctx.line, ' ') == nil then return 3 end
return 0
end
}
}
}