Skip to content

How can I call functions inside the mapping function silently? #616

Answered by hrsh7th
smjonas asked this question in Q&A
Discussion options

You must be logged in to vote

The feedkeys isn't support silent. So this problem is a bit complex to solve.

  1. You should define mapping.
inoremap <silent> <Plug>(my-ultisnips-expand) <C-r>=[UltiSnips#CursorMoved(), UltiSnips#ExpandSnippet()][1]<CR>
  1. Then you can feed plug map.
local t = function(keys, mode)
  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, true, true), mode or 'n', true)
end

...

  ["<Tab>"] = cmp.mapping(function(fallback)
    if cmp.get_selected_entry() == nil and vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
      t('<Plug>(my-ultisnips-expand)', '')
    elseif vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
      ...
    end
  )

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@smjonas
Comment options

@hrsh7th
Comment options

@smjonas
Comment options

@hrsh7th
Comment options

@smjonas
Comment options

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