Giter Site home page Giter Site logo

Comments (7)

smjonas avatar smjonas commented on August 16, 2024

Which key do you press to expand the snippet? Right now, jumping to the next placeholder only works if the snippet was already expanded (the item was selected from cmp's menu). The default in cmp is <cr> by the way.

For example, I have this mapping:

    ["<C-f>"] = cmp.mapping(
      cmp.mapping.confirm {
        behavior = cmp.ConfirmBehavior.Replace,
        select = true,
      },
      { "i", "s" }
    ),

from cmp-nvim-ultisnips.

Guzzii avatar Guzzii commented on August 16, 2024

I am having a similar issue, potentially the same. I am using return to expand snippets, and also set tab and s-tab to jump forward and backward like mentioned above. After expended a snippet, the cursor jumps to the first placeholder in select mode waiting for user input.

  • If I replace the placeholder text by typing a few characters, I am then in insert mode. Tab will jump to the next placeholder with no problem
  • However, if I press tab to jump the second placeholder without typing anything (essentially still in select mode), it will not jump. Instead, the tab kicks me out of select mode and goes into normal mode.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

@Guzzii could you share your nvim-cmp config? It might be a configuration issue because I can't reproduce it (<Tab> moves me to the next placeholder even in select mode).

from cmp-nvim-ultisnips.

Guzzii avatar Guzzii commented on August 16, 2024

Sure, below is my config

vim.cmd('set completeopt=menu,menuone,noselect')

local cmp = require('cmp')
local lspkind = require('lspkind')
local cmp_ultisnips_mappings = require('cmp_nvim_ultisnips.mappings')

cmp.setup({
  snippet = {
    -- REQUIRED - you must specify a snippet engine
    expand = function(args)
      vim.fn['UltiSnips#Anon'](args.body) -- For `ultisnips` users.
    end,
  },
  sources = cmp.config.sources({
    { name = 'nvim_lsp' }, { name = 'ultisnips' },
    { name = 'buffer' }, { name = 'nvim_lua' },
    { name = 'tmux' }, { name = 'emoji' }
  }),
  mapping = {
    ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
    ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
    ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
    ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
    ['<C-e>'] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }),
    ['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    ['<Tab>'] = cmp.mapping(
      function(fallback)
        cmp_ultisnips_mappings.compose {'select_next_item', 'jump_forwards'}(fallback)
      end, {'i', 's'}
    ),
    ['<S-Tab>'] = cmp.mapping(
      function(fallback)
        cmp_ultisnips_mappings.compose {'select_prev_item', 'jump_backwards'}(fallback)
      end, {'i', 's'}
    ),
    ['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i', 's', 'c'}),
    ['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's', 'c'}),
  },
  formatting = {
    format = lspkind.cmp_format({
      with_text = true,
      menu = {
        buffer = '[Buffer]',
        nvim_lsp = '[LSP]',
        nvim_lua = '[Lua]',
        ultisnips = '[UltraSnip]',
        tmux = '[Tmux]',
        emoji = '[Emoji]',
      }
    }),
  },
})

-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', { sources = {{ name = 'buffer' }}})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  sources = cmp.config.sources({{ name = 'path' }}, {{ name = 'cmdline' }})
})

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Sorry, I still can't reproduce it with your config. For some reason, setting <cr> as the key to confirm the selected item does not even work for me (it does not expand the snippet). Can you check that smap <Plug> contains the three mappings cmpu-expand, cmpu-jump-forwards and cmpu-jump-backwards?

from cmp-nvim-ultisnips.

Guzzii avatar Guzzii commented on August 16, 2024

Just to confirm, with the latest update, it is working as expected and no longer an issue.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Perfect, thanks for letting me know!

from cmp-nvim-ultisnips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.