quangnguyen30192 / cmp-nvim-ultisnips

nvim-cmp source for ultisnips
Apache License 2.0
145 stars 19 forks source link

add a new mapping function? #45

Closed mathjiajia closed 2 years ago

mathjiajia commented 2 years ago

Hi, thanks for this fantastic plugin.

Since I do not want to integrate too many functions in the Tab key. Actually , I use the default jump key of UltiSnips, which is C+J. Could you add a new function expand(fallback).

Something like below:

function M.expand(fallback)
   if cmp.get_selected_entry() == nil and vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
     t("<Plug>(cmpu-expand)")
   elseif cmp.visible() then
     cmp.select_next_item()
   else
     fallback()
   end
 end

Thanks

smjonas commented 2 years ago

I think this is a nice idea for users that prefer separate mappings for jumping between tabstops and selecting the next completion item. Still, I would argue that expand_or_jump_forward should be the default for new users since it feels intuitive. Would you agree? I think I will add this later (but the readme will also have to be updated).

quangnguyen30192 commented 2 years ago

I would argue that expand_or_jump_forward should be the default for new users since it feels intuitive

I feel good 👍 let's do it

mathjiajia commented 2 years ago

I think this is a nice idea for users that prefer separate mappings for jumping between tabstops and selecting the next completion item. Still, I would argue that expand_or_jump_forward should be the default for new users since it feels intuitive. Would you agree? I think I will add this later (but the readme will also have to be updated).

Thank you.

smjonas commented 2 years ago

Once #48 is merged (soon), you can achieve your desired behaviour like this:

["<Tab>"] = cmp.mapping(
  function(fallback)
    cmp_ultisnips_mappings.compose({ "expand", "select_next_item" })(fallback)
  end,
  { "i", "s", [[ "c" to enable the mapping in command mode ]] }
),
["<S-Tab>"] = cmp.mapping(
  function(fallback)
    cmp_ultisnips_mappings.compose({ "select_prev_item" })(fallback)
  end,
  { "i", "s", [[ "c" to enable the mapping in command mode ]] }
)
mathjiajia commented 2 years ago

Thank you so much. That looks great!