The idea is to have a keybinding, which executes a lua/vimscript function to paste yanked text into the command line and then have the command completion showing suggestions or directly get the command completions for selection from a keymap.
One example is the following lua command to switch to a material design:
local add_cmd = vim.api.nvim_create_user_command
add_cmd('Style',
function(opts)
require('material.functions').change_style(opts.args)
end, {
nargs = 1,
complete = function(_, _, _)
return { "darker", "lighter", "palenight", "oceanic", "deep ocean" }
end,
}
)
The keymap for <leader>ma
should paste :Style
to the command line with the tab to have command completion showing up or call the completion function directly to resolve what should be completed.
This answer describes how to paste yanked text into the command line https://stackoverflow.com/questions/3997078/how-to-paste-yanked-text-into-the-vim-command-line visually.
Neovim shows me that the lua keybinding is invalid without <CR>
, so I guess that I can not use the neovim API for that.
Related: Is there another way to fire the completion function for the command to resolve what argument should be used for the command before execution in the command line?
:nnoremap <leader>ma :set wildcharm=<C-z><CR>:Style <C-z>
(I think)getcompletion()