Skip to content

How to complete and enter at the same time in cmdline mode? #1484

Answered by fitrh
rieje asked this question in Q&A
Discussion options

You must be logged in to vote

Logically, in terms of cmdline, cmp.confirm only confirms (i.e. select then insert) the selection, and it has nothing to do with executing the command, so you need to confirm it and then feed the CR to execute the command

["<CR>"] = cmp.mapping({
  i = function(fallback)
    if cmp.visible() and cmp.get_selected_entry() then
      return cmp.confirm({ select = true })
    end

    fallback()
  end,
  c = function(fallback)
    if cmp.visible() and cmp.get_selected_entry() then
      cmp.confirm({ select = true })
      local CR = vim.api.nvim_replace_termcodes("<CR>", true, true, true)
      return vim.api.nvim_feedkeys(CR, "n", true)
    end

    fallback()
  end,
}),

if I don't specify…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by rieje
Comment options

You must be logged in to vote
7 replies
@Maltimore
Comment options

@fitrh
Comment options

@Maltimore
Comment options

@fitrh
Comment options

@Maltimore
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants