Shougo / neopairs.vim

Auto insert pairs when complete done
31 stars 1 forks source link

support for jump out of pairs. #1

Closed wsdjeg closed 8 years ago

wsdjeg commented 8 years ago

i think it is better supprt this feature,and also it is not hard to implement. for example complete a method test( after type any char or space will get test(_) _ is cursor then i think sould provid a map to jump out of pairs i can map my type

imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : (pumvisible() ?
\ "\<C-n>" : (jumpoutofpairsable() ?
\ "\<Plug>(neopairs_jump_out)" : "\<TAB>"))
Shougo commented 8 years ago

You should use neosnippet feature. Closing.

wsdjeg commented 8 years ago

the '(' comes from completion ,not typed by myself,does neosnippet support this?

wsdjeg commented 8 years ago

thanks,it works,

wsdjeg commented 8 years ago

some thing must be wrong, _ is cursor this. type tab --> this.wait( type Enter --> this.wait( ) type tab this.wait(wait)<0>) here an ) is extra

wsdjeg commented 8 years ago

@Shougo I have found why we get the error,if I use deoplete neopairs.vim and neosnippet.vim together,something will be error. after competion,if the words end with a (,neopairs will add an ) and put the cursor between them ,then if you type tab, neosnippet.vim will expand the first ( to (${1})${0} but do not delete the second ) so there will be an extra )

Shougo commented 8 years ago

@wsdjeg Please provide the minimal init.vim and reproduce ways from Vim starting. I will check it.

wsdjeg commented 8 years ago
NeoBundle 'Shougo/deoplete.nvim'
let s:hooks = neobundle#get_hooks("deoplete.nvim")
function! s:hooks.on_source(bundle)
    let g:deoplete#enable_at_startup = 1
    let g:deoplete#enable_ignore_case = 1
    let g:deoplete#enable_smart_case = 1
    let g:deoplete#enable_fuzzy_completion = 1
    let g:deoplete#omni#input_patterns = get(g:,'deoplete#omni#input_patterns',{})
    let g:deoplete#omni#input_patterns.java = [
                \'[^. \t0-9]\.\w*',
                \'[^. \t0-9]\->\w*',
                \'[^. \t0-9]\::\w*',
                \'\s[A-Z][a-z]',
                \'^\s*@[A-Z][a-z]'
                \]
    let g:deoplete#omni#input_patterns.jsp = ['[^. \t0-9]\.\w*']
    inoremap <expr><C-h> deolete#mappings#smart_close_popup()."\<C-h>"
    inoremap <expr><BS> deoplete#mappings#smart_close_popup()."\<C-h>"
endf
NeoBundle 'Shougo/neco-syntax'
NeoBundle 'Shougo/context_filetype.vim'
NeoBundle 'Shougo/neoinclude.vim'
NeoBundle 'Shougo/neopairs.vim'
NeoBundle 'Shougo/neosnippet-snippets'
NeoBundle 'Shougo/neosnippet.vim' "{{{
let g:neosnippet#snippets_directory='~/DotFiles/snippets'
let g:neosnippet#enable_snipmate_compatibility=1

imap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : (pumvisible() ? "\<C-n>" : "\<TAB>")
smap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
imap <expr><S-TAB> pumvisible() ? "\<C-p>" : ""
smap <expr><S-TAB> pumvisible() ? "\<C-p>" : ""
inoremap <silent> <CR> <C-r>=MyEnterfunc()<Cr>
NeoBundle 'wsdjeg/vim-javacomplete2'
let g:JavaComplete_UseFQN = 1
let g:JavaComplete_ServerAutoShutdownTime = 300
let g:JavaComplete_MavenRepositoryDisable = 0
function MyEnterfunc()
    if pumvisible()
        if s:settings.autocomplete_method == 'neocomplete'||s:settings.autocomplete_method == 'deoplete'
            return "\<C-y>"
        else
            return "\<esc>a"
        endif
    elseif getline('.')[col('.') - 2]=="{"&&getline('.')[col('.')-1]=="}"
        return "\<Enter>\<esc>ko"
    else
        return "\<Enter>"
    endif
endf
  1. vim Foo.java type
class Foo{
this_//cursor
}

then type dot,will show all the methon,if i chooce any one which is end with (,the neopairs will aotu add )after cursor,then if i type tab ,neosnippet.vim will expand the first ( to (${1})${0} but do not delete the second ) so there will be an extra )

Shougo commented 8 years ago

OK. I fixed the conflict. But you should not enable neopairs if you want to jump out of pairs by neosnippet.

wsdjeg commented 8 years ago

what is the significance of neopairs,i think neosnippet need start manully,and only can be start after a left pair,if after complete a method,i have typed some chars,then type tab will not start neosnippet. i think the best solution is : when finish completion,and the output word ends with a pair,neopairs aoto complete the right pair,and efine a variable x = 1,if i complete anothe method between the pairs ,the x++, the we can use this fun if x > 0 jump to the right of the first right pair,and x--, until x == 0 we can not jump

wsdjeg commented 8 years ago

i find you just pushed a commit , i will have a try

wsdjeg commented 8 years ago

ahaha, that means we should not use neopairs and neosnippet togther with deoplete?

Shougo commented 8 years ago

Yes... It is wired behaviour though.

wsdjeg commented 8 years ago

ok let me put neopairs into neocomplete gloups,and try with this latest version of neosnippet.vim

wsdjeg commented 8 years ago

somithing error, after completion ,if i type tab,the cursor will jump out of pairs instead of in it.

Shougo commented 8 years ago

@wsdjeg Your description is always too short. Please more described information.

wsdjeg commented 8 years ago

ok, sorry,the position checking maybe error, after completion,if I type tab the cursor will move to next position of pairs,like this()_, then type tab again ,the cursor just move one step,like this()\s\ _,but then type tab again the cursor will move four step which is set by me,like this()\s\s\s\s\s\ _,

Shougo commented 8 years ago

Cannot understand.

Please create minimal .vimrc. And your previous described .vimrc is too long. It must be less than 20 lines.

wsdjeg commented 8 years ago

sorry i it is not due to vimrc,but if you want ,i will reduce it

NeoBundle 'Shougo/deoplete.nvim'
let g:deoplete#enable_at_startup = 1
let g:deoplete#omni#input_patterns = get(g:,'deoplete#omni#input_patterns',{})
let g:deoplete#omni#input_patterns.java = ['[^. \t0-9]\.\w*']
NeoBundle 'Shougo/neosnippet.vim' "{{{

imap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : (pumvisible() ? "\<C-n>" : "\<TAB>")
smap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
inoremap <silent> <CR> pumvisible()? "\<c-y>" : "\<cr>"
NeoBundle 'wsdjeg/vim-javacomplete2'
let g:JavaComplete_UseFQN = 1
let g:JavaComplete_ServerAutoShutdownTime = 300
let g:JavaComplete_MavenRepositoryDisable = 0

as you wantted, after complete a omnifunc, the text should be this,wait( then you type tab,will star snippet's autopairs,after this,the cursor should stay between pairs,then type tab jump out.but now after this.wait( if I type tab will get this.wait()_the cursor is out of pairs

wsdjeg commented 8 years ago

the next time i type tab the cursor move one step to right ,next time move four step to right,as i have set tabstop = 4

wsdjeg commented 8 years ago

maybe i have misunderstand you ,after testting many times i found maybe you just do not want to let the cursor stay between the pairs,but jump directory out of the pairs,and star to input another chars

Shougo commented 8 years ago

@wsdjeg I don't want to test javacomplete2. Please create another example without javacomplete2. Recommend is neco-vim.

wsdjeg commented 8 years ago

sorry i have test neco-vim ,it works different from java omni,and it works well

Shougo commented 8 years ago

I have improved neosnippet behavior. You must set let g:neosnippet#enable_complete_done = 1 option to expand it.

wsdjeg commented 8 years ago

@Shougo @artur-shaik hi man ,I think i have kown why it does not work,neosnippet's auto jump between args and out of pairs based on the completion word, for example if the completion word is test(args1,args2),after finish completion,we can use tab jump form args1 to args2,then we also can use tab jump out of pairs.but in javacomplete2,the method's complete word is only test(,the args and return type show in the pop menu,not in complete word. it is diff feature between jc2 and neosnippet,is my understanding wrong??

wsdjeg commented 8 years ago

2015-12-12 10-18-04 2015-12-12 10-18-08 2015-12-12 10-18-14 2015-12-12 10-18-19

wsdjeg commented 8 years ago

these three above pic we just need to type tab three times

wsdjeg commented 8 years ago

@artur-shaik @Shougo you see in Javacomplete2 all method has no args,show we add args into complete words? 2015-12-12 10-30-25

wsdjeg commented 8 years ago

if i set let g:neosnippet#enable_complete_done = 1, can not use tab select item, when i do not close the pumvisible i type tab once will get 2015-12-12 10-44-11 type tab again 2015-12-12 10-44-56 type tab again 2015-12-12 10-44-17

Shougo commented 8 years ago

you see in Javacomplete2 all method has no args,show we add args into complete words?

Fixed the problem.

wsdjeg commented 8 years ago

haha thanks very much,and it works perfectly. and @artur-shaik should know it,let me show you some pic;

after this type dot

2015-12-12 19-05-15

type e

2015-12-12 19-05-21

type tab

2015-12-12 19-05-25

type Entrer

2015-12-12 19-05-31

type tab ( here before type tab you also can input some other chars,after inputting chars use tab jump out of pairs)

2015-12-12 19-05-39

wsdjeg commented 8 years ago

it is really perfect,if no args,after type Enter,the pairs auto complete ,the cursor auto jump out,it works very well, @mattn i remamber you open a same issue in javacomplete2,in that issue ,you want complete ),when has no args, i think ,you can have a try with shougo's plugin