Shougo / neosnippet.vim

neo-snippet plugin
Other
1.12k stars 108 forks source link

Lost place holder when inputs <CR> #436

Closed leico closed 6 years ago

leico commented 6 years ago

definitions

#### block
snippet {}
alias   block_literal
abbr    block/struct
{ ${1:#:contents} }${0}
## struct
snippet struct
abbr    struct instance statement
struct ${1:#:typename} ${2:#:variable_or_process}${0}
#### functions

snippet function
alias   func
abbr    function declaration
  ${1:#:type} ${2:#:function name} ( ${3:#:args} ) ${4:#:process}

toml

# deoplete------------------

[[plugins]]
repo = 'Shougo/deoplete.nvim'
hook_add = '''
let g:deoplete#enable_at_startup   = 1

inoremap <expr><tab> pumvisible() ? "\<C-n>" :
        \ neosnippet#expandable_or_jumpable() ?
        \    "\<Plug>(neosnippet_expand_or_jump)" : "\<tab>"

inoremap <expr><S-Tab> pumvisible() ? deoplete#close_popup() : "\<S-Tab>"
'''

hook_post_source = '''
call deoplete#custom#option({
\    'auto_complete_delay' : 0
\  , 'min_pattern_length'  : 1
\  })
'''
on_i = 1

# neosnippet----------------

[[plugins]]
repo = 'Shougo/neosnippet.vim'
depends = [
    'neosnippet-snippets'
  , 'context_filetype.vim'
]
on_i = 1
hook_source = '''
" Plugin key-mappings.
" Note: It must be "imap" and "smap".  It uses <Plug> mappings.
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)

" SuperTab like snippets behavior.
" Note: It must be "imap" and "smap".  It uses <Plug> mappings.
imap <expr><TAB>
 \ pumvisible() ? "\<C-n>" :
 \ neosnippet#expandable_or_jumpable() ?
 \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

imap <expr><CR>
\ (pumvisible() && neosnippet#expandable()) ? "\<Plug>(neosnippet_expand_or_jump)" : "\<CR>"

smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

" For conceal markers.
"if has('conceal')
"  set conceallevel=2 concealcursor=niv
'''

# neosnippet-cpp----------------
[[plugins]]
repo = 'leico/neosnippet-cpp'
on_ft   = ['c', 'cpp']
depends = ['neosnippet.vim']
hook_source = '''
let g:neosnippet#snippets_directory = '~/.config/nvim/dein/repos/github.com/leico/neosnippet-cpp/snippets'
let g:neosnippet#disable_runtime_snippets = { 'c' : 1, 'cpp' : 1 }
'''

situation

struct

function

place holder を埋めている最中に改行を入れると、後ろの place holder が消失してしまいます。 これを解決する方法はありますでしょうか。

Shougo commented 6 years ago
imap <expr><CR>
\ (pumvisible() && neosnippet#expandable()) ? "\<Plug>(neosnippet_expand_or_jump)" : "\<CR>"

これが原因だと思います。事故のもとなので <CR> による自動展開しないほうがよいです。

leico commented 6 years ago

お返事ありがとうございます。 指摘していただきました <CR>のキーマップを消去し、Vimを再起動してみましたが症状が発生いたしました・・・。

function2

Shougo commented 6 years ago

OK. I will try it later.

leico commented 6 years ago

お手数をおかけいたします。

:map の出力も送付いたします。

s  <Tab>         neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<Tab>"                                     
x  <C-K>         <Plug>(neosnippet_expand_target)                                                                                          
s  <C-K>         <Plug>(neosnippet_expand_or_jump)                                                                                         
o  %           * v:<C-U>call <SNR>22_Match_wrapper('',1,'o') <CR>                                                                          
v  %           * :<C-U>call <SNR>22_Match_wrapper('',1,'v') <CR>m'gv``                                                                     
n  %           * :<C-U>call <SNR>22_Match_wrapper('',1,'n') <CR>                                                                           
o  [%          * v:<C-U>call <SNR>22_MultiMatch("bW", "o") <CR>                                                                            
v  [%            <Esc>[%m'gv``                                                                                                             
n  [%          * :<C-U>call <SNR>22_MultiMatch("bW", "n") <CR>                                                                             
o  ]%          * v:<C-U>call <SNR>22_MultiMatch("W",  "o") <CR>                                                                            
v  ]%            <Esc>]%m'gv``                                                                                                             
n  ]%          * :<C-U>call <SNR>22_MultiMatch("W",  "n") <CR>                                                                             
v  a%            <Esc>[%v]%                                                                                                                
v  gx            <Plug>NetrwBrowseXVis                                                                                                     
n  gx            <Plug>NetrwBrowseX                                                                                                        
o  g%          * v:<C-U>call <SNR>22_Match_wrapper('',0,'o') <CR>                                                                          
v  g%          * :<C-U>call <SNR>22_Match_wrapper('',0,'v') <CR>m'gv``                                                                     
n  g%          * :<C-U>call <SNR>22_Match_wrapper('',0,'n') <CR>                                                                           
x  <Plug>(neosnippet_register_oneshot_snippet) * :<C-U>call neosnippet#mappings#_register_oneshot_snippet()<CR>                            
x  <Plug>(neosnippet_expand_target) * :<C-U>call neosnippet#mappings#_expand_target()<CR>                                                  
x  <Plug>(neosnippet_get_selected_text) * :call neosnippet#helpers#get_selected_text(visualmode(), 1)<CR>                                  
s  <Plug>(neosnippet_jump) * neosnippet#mappings#jump_impl()                                                                               
s  <Plug>(neosnippet_expand) * neosnippet#mappings#expand_impl()                                                                           
s  <Plug>(neosnippet_jump_or_expand) * neosnippet#mappings#jump_or_expand_impl()                                                           
s  <Plug>(neosnippet_expand_or_jump) * neosnippet#mappings#expand_or_jump_impl()                                                           
v  <Plug>NetrwBrowseXVis * :<C-U>call netrw#BrowseXVis()<CR>                                                                               
n  <Plug>NetrwBrowseX * :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())<CR>  
Shougo commented 6 years ago

Please disable g#neosnippet#enable_auto_clear_markers.

leico commented 6 years ago

Thank you! It works!!

typedef

and receiving your advice, changed key mapping from CR to Tab.

typedef2

Little bit strange jumping but no problem I guess.