hrsh7th / vim-vsnip

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

After expand, mode change to normal. (from select pooups) #255

Closed iranoan closed 1 year ago

iranoan commented 2 years ago

absturuct

After expand, mode change to normal.

enviroment

\~/.vim/vimrc

call plug#begin()
Plug 'junegunn/vim-plug'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'rafamadriz/friendly-snippets'
call plug#end()
imap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'
smap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'
imap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
set viminfo+=n~/.vim/viminfo
set background=dark
colorscheme desert
filetype plugin on
set laststatus=2
" The below setting has nothing to do with the issue.
" To make it easier to understand the mode in the video.
augroup InsertStatus
  autocmd!
  autocmd InsertEnter * highlight StatusLine ctermfg=red   guibg=red
  autocmd InsertLeave * highlight StatusLine ctermfg=white guibg=white
augroup END

Vim version

LANGUAGE=C vim --version VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 13 2022 09:35:02) Included patches: 1-3995, 4563, 4646, 4774, 4895, 4899, 4901, 4919 Modified by team+vim@tracker.debian.org Compiled by team+vim@tracker.debian.org Huge version with GTK3 GUI. Features included (+) or not (-):

OS

$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy $ uname -a Linux xxxx 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

reproduction steps

vsni

  1. insert full-spell (prefix)
  2. \ (vsnip-expand-or-jump) -> insert mode
  3. type insert -> All will be entered.

This behavior is what I expect.

Otherwise

  1. inset prefix
  2. select from popups
  3. \ (vsnip-expand-or-jump) -> normal mode
  4. type insert -> No i is entered.

add information

Fix example?

vim-vsnip/plugin/vsnip.vim L.96

  " This is needed to keep normal-mode during 0ms to prevent CompleteDone handling by LSP Client.
  let l:maybe_complete_done = !empty(v:completed_item) && !empty(v:completed_item.user_data)
  if l:maybe_complete_done
    call timer_start(0, { -> l:ctx.callback() })
  else

change to

  " This is needed to keep normal-mode during 0ms to prevent CompleteDone handling by LSP Client.
  let l:maybe_complete_done = !empty(v:completed_item) && !empty(v:completed_item.user_data)
  if l:maybe_complete_done
    call timer_start(0, { -> l:ctx.callback() })
    if mode(1) =~# 'n'
      startinsert
    endif
  else
hrsh7th commented 1 year ago

Hm... I can't reproduce with your minimal config.

https://user-images.githubusercontent.com/629908/195973864-682be1b5-5b3c-4cc1-b98d-297b7d9008e3.mov

iranoan commented 1 year ago

Sorry. mapping Not enough ().

scriptversion 4
call plug#begin()
Plug 'junegunn/vim-plug'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'rafamadriz/friendly-snippets'
call plug#end()
imap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'
smap <expr> <C-j>   vsnip#expandable()  ? '<Plug>(vsnip-expand)'         : '<C-j>'
imap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
" map additional beginning
imap <expr> <C-y>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-y>'
smap <expr> <C-y>   vsnip#available(1)  ? '<Plug>(vsnip-expand-or-jump)' : '<C-y>'
" map additional ending
set viminfo+=n~/.vim/viminfo
set background=dark
" The below setting has nothing to do with the issue.
" To make it easier to understand the mode in the video.
colorscheme desert
filetype plugin on
set laststatus=2
augroup InsertStatus
  autocmd!
  autocmd InsertEnter * highlight StatusLine ctermfg=red   guibg=red
  autocmd InsertLeave * highlight StatusLine ctermfg=white guibg=white
augroup END
hrsh7th commented 1 year ago

Fixed by abfe8411a0d1c0dfea56b7221e49cbb6cf7cf4fe

iranoan commented 1 year ago

Thanks. confirm to fix