hrsh7th / vim-vsnip

Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
MIT License
880 stars 37 forks source link

Selection always miss the last character #222

Closed AgentCosmic closed 2 years ago

AgentCosmic commented 3 years ago

For example:

for (let index = 0; index < array.length; index++) {
    const element = array[index];

}

My first selection will be inde, but not index. Then I jump to next position arra, again missing the y. I'm using it with nvim-cmp. Neovim 5.1 Windows.

hrsh7th commented 3 years ago

Please minimal reproducible steps.

AgentCosmic commented 3 years ago

This is my init.vim

" This is the folder where we'll store all the files
" set environment variable $env:XDG_CONFIG_HOME="D:/Applications/Neovim"
let $ROOT = expand('D:/Applications/Neovim/nvim')
set runtimepath+=$ROOT
" we reset $HOME directory here so plugins won't dirty our real home directory
let $HOME = $ROOT . '/home'

runtime mswin.vim

call plug#begin('$HOME/plugged')
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'rafamadriz/friendly-snippets' " snippets
call plug#end()

" nvim-cmp
set completeopt=menu,menuone,noselect
lua << EOF
local cmp = require'cmp'
cmp.setup({
    mapping = {
        ['<tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
        ['<s-tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 's' }),
        ['<c-space>'] = cmp.mapping.complete(),
        ['<cr>'] = cmp.mapping.confirm({ select = true }),
        ['<c-d>'] = cmp.mapping.scroll_docs(-4),
        ['<c-f>'] = cmp.mapping.scroll_docs(4),
    },
    sources = {
        { name = 'vsnip' },
    },
    snippet = {
        expand = function(args)
            vim.fn["vsnip#anonymous"](args.body)
        end,
    },
})
EOF

" vsnip
imap <expr> <c-s-n>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<c-s-n>'
smap <expr> <c-s-n>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<c-s-n>'

I open any javascript/typescript/python/css file. Then I type something like for and choose the snippet. But I noticed after working for a while, sometimes the selection works correctly.

AgentCosmic commented 2 years ago

Hello, is there anything I can help you to debug this more easily?

JimmyHuang454 commented 2 years ago

Same issuse happens to me. vim8.2 in Windows.

{
  "Class": {
    "prefix": ["let"],
    "body": [
      "let ${1:name} = $0"
    ]
  }
}

After triggered: 搜狗截图20211218230044

Expect: 搜狗截图20211218230222

hrsh7th commented 2 years ago

@JimmyHuang454 I think the name will replace to a If you press a with After triggered: condition. If so It's expected behavior.

JimmyHuang454 commented 2 years ago

I am new to vsnip, just starting in today. And I just want vsnip works as ultisnips: 动画

the first let in the gif is triggered by vsnip, the second one is triggered by ultisnips.

My vimrc:

Plug 'hrsh7th/vim-vsnip'

let g:vsnip_snippet_dir = 'D:/Vim/test_snip'

" Expand or jump
imap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'