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
  end, {
    nargs = 1,
    complete = function(_, _, _)
      return { "darker", "lighter", "palenight", "oceanic", "deep ocean" }

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?

  • I know that I could also use telescope for this, but I would like a smaller solution for less distraction and I am curious on the command-line completion limitations.
    – Jay-Pi
    Commented Oct 20, 2022 at 8:21
  • 1
    In Vim, the general approach would be something like :nnoremap <leader>ma :set wildcharm=<C-z><CR>:Style <C-z> (I think)
    – D. Ben Knoble
    Commented Oct 20, 2022 at 13:06
  • 1
    There is also getcompletion()
    – D. Ben Knoble
    Commented Oct 20, 2022 at 13:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.