57726

[code]

    set completeopt+=noselect
    set completeopt-=preview
    let g:deoplete#enable_at_startup = 1
    let g:deoplete#auto_complete_delay = 0
    let g:deoplete#auto_complete_start_length = 1
    inoremap <expr><C-h> deoplete#smart_close_popup()."\<C-h>"
    inoremap <expr><BS>  deoplete#smart_close_popup()."\<C-h>"
    inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
    function! s:my_cr_function() abort
      return deoplete#close_popup() . "\<CR>"
    endfunction
    
[/code]

my_cr_functionにおいてnoselectなら

[code]

    deoplete#close_popup() . "\<CR>"
    
[/code]

候補のいずれかが選択されていたら

[code]

    deoplete#close_popup()
    
[/code]

としたい.  
help見てもselectedを取得するインターフェースが見つからなかった.

追記  
解決した.

[code]

    NVIM v0.3.8
    Build type: Release
    LuaJIT 2.0.5
    Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.3.8/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
    Compiled by builduser
    
    Features: +acl +iconv +jemalloc +tui 
    See ":help feature-compile"
    
          システム vimrc: "$VIM/sysinit.vim"
           省略時の $VIM: "/usr/share/nvim"
    
    Run :checkhealth for more info
    
[/code]

[code]

    VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 29 2019 20:38:53)
    適用済パッチ: 1-1776
    Compiled by Arch Linux
    Huge 版 without GUI.  機能の一覧 有効(+)/無効(-)
    +acl               -farsi             -mouse_sysmouse    -tag_any_white
    +arabic            +file_in_path      +mouse_urxvt       +tcl/dyn
    +autocmd           +find_in_path      +mouse_xterm       +termguicolors
    +autochdir         +float             +multi_byte        +terminal
    -autoservername    +folding           +multi_lang        +terminfo
    -balloon_eval      -footer            -mzscheme          +termresponse
    +balloon_eval_term +fork()            +netbeans_intg     +textobjects
    -browse            +gettext           +num64             +textprop
    ++builtin_terms    -hangul_input      +packages          +timers
    +byte_offset       +iconv             +path_extra        +title
    +channel           +insert_expand     +perl/dyn          -toolbar
    +cindent           +job               +persistent_undo   +user_commands
    -clientserver      +jumplist          +postscript        +vartabs
    -clipboard         +keymap            +printer           +vertsplit
    +cmdline_compl     +lambda            +profile           +virtualedit
    +cmdline_hist      +langmap           +python/dyn        +visual
    +cmdline_info      +libcall           +python3/dyn       +visualextra
    +comments          +linebreak         +quickfix          +viminfo
    +conceal           +lispindent        +reltime           +vreplace
    +cryptv            +listcmds          +rightleft         +wildignore
    +cscope            +localmap          +ruby/dyn          +wildmenu
    +cursorbind        +lua/dyn           +scrollbind        +windows
    +cursorshape       +menu              +signs             +writebackup
    +dialog_con        +mksession         +smartindent       -X11
    +diff              +modify_fname      -sound             -xfontset
    +digraphs          +mouse             +spell             -xim
    -dnd               -mouseshape        +startuptime       -xpm
    -ebcdic            +mouse_dec         +statusline        -xsmp
    +emacs_tags        +mouse_gpm         -sun_workshop      -xterm_clipboard
    +eval              -mouse_jsbterm     +syntax            -xterm_save
    +ex_extra          +mouse_netterm     +tag_binary        
    +extra_search      +mouse_sgr         -tag_old_static    
          システム vimrc: "/etc/vimrc"
          ユーザー vimrc: "$HOME/.vimrc"
       第2ユーザー vimrc: "~/.vim/vimrc"
           ユーザー exrc: "$HOME/.exrc"
      デフォルトファイル: "$VIMRUNTIME/defaults.vim"
           省略時の $VIM: "/usr/share/vim"
    コンパイル: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -D_FORTIFY_SOURCE=2  -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
    リンク: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lelf -lnsl    -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.30/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm     
    
[/code]

[code]

    echo completed_info()
    
[/code]

vimだと値返ってくるがnvimだと未知の関数  
helpにもない

[code]

    echo v:completed_item
    
[/code]

どちらにも存在した

[code]

    imap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
    let g:cache_completed = {}
    function! s:my_cr_function() abort
      if has_key(v:completed_item, 'word') && g:cache_completed != v:completed_item
        let g:cache_completed = v:completed_item
        return deoplete#close_popup()
      else
        return deoplete#close_popup() . "\<CR>"
      endif
    endfunction
    
[/code]


CC BY-SA 4.0
2019-08-30T03:01:26.617
57711
2022-08-19T01:48:32.650
2022-08-19T01:48:32.650
3060
35654
question
vim neovim
deoplete.nvim 選択されているindexを取得したい


新しい Vim/neovim ならば `complete_info()` を用いるのがよいと思います。

`:help complete_info()`


CC BY-SA 4.0
2019-08-31T04:28:54.763
57726
2019-08-31T04:28:54.763
14351
57711
answer


解決した. denite.nvimのヘルプしか見てなかったが, vim標準の補完機能のインターフェースが使えた.

[code]

    echo completed_info()
    
[/code]

vimだと値返ってくるがnvimだと未知の関数でhelpにもない.  
versionは下記

[code]

    echo v:completed_item
    
[/code]

どちらにも存在した.  
これをもって以下のように書いた.

[code]

    imap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
    let g:cache_completed = {}
    function! s:my_cr_function() abort
      if has_key(v:completed_item, 'word') && g:cache_completed != v:completed_item
        let g:cache_completed = v:completed_item
        return deoplete#close_popup()
      else
        return deoplete#close_popup() . "\<CR>"
      endif
    endfunction
    
[/code]

## version

[code]

    NVIM v0.3.8
    Build type: Release
    LuaJIT 2.0.5
    Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.3.8/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
    Compiled by builduser
    
    Features: +acl +iconv +jemalloc +tui 
    See ":help feature-compile"
    
          システム vimrc: "$VIM/sysinit.vim"
           省略時の $VIM: "/usr/share/nvim"
    
    Run :checkhealth for more info
    
[/code]

[code]

    VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 29 2019 20:38:53)
    適用済パッチ: 1-1776
    Compiled by Arch Linux
    Huge 版 without GUI.  機能の一覧 有効(+)/無効(-)
    +acl               -farsi             -mouse_sysmouse    -tag_any_white
    +arabic            +file_in_path      +mouse_urxvt       +tcl/dyn
    +autocmd           +find_in_path      +mouse_xterm       +termguicolors
    +autochdir         +float             +multi_byte        +terminal
    -autoservername    +folding           +multi_lang        +terminfo
    -balloon_eval      -footer            -mzscheme          +termresponse
    +balloon_eval_term +fork()            +netbeans_intg     +textobjects
    -browse            +gettext           +num64             +textprop
    ++builtin_terms    -hangul_input      +packages          +timers
    +byte_offset       +iconv             +path_extra        +title
    +channel           +insert_expand     +perl/dyn          -toolbar
    +cindent           +job               +persistent_undo   +user_commands
    -clientserver      +jumplist          +postscript        +vartabs
    -clipboard         +keymap            +printer           +vertsplit
    +cmdline_compl     +lambda            +profile           +virtualedit
    +cmdline_hist      +langmap           +python/dyn        +visual
    +cmdline_info      +libcall           +python3/dyn       +visualextra
    +comments          +linebreak         +quickfix          +viminfo
    +conceal           +lispindent        +reltime           +vreplace
    +cryptv            +listcmds          +rightleft         +wildignore
    +cscope            +localmap          +ruby/dyn          +wildmenu
    +cursorbind        +lua/dyn           +scrollbind        +windows
    +cursorshape       +menu              +signs             +writebackup
    +dialog_con        +mksession         +smartindent       -X11
    +diff              +modify_fname      -sound             -xfontset
    +digraphs          +mouse             +spell             -xim
    -dnd               -mouseshape        +startuptime       -xpm
    -ebcdic            +mouse_dec         +statusline        -xsmp
    +emacs_tags        +mouse_gpm         -sun_workshop      -xterm_clipboard
    +eval              -mouse_jsbterm     +syntax            -xterm_save
    +ex_extra          +mouse_netterm     +tag_binary        
    +extra_search      +mouse_sgr         -tag_old_static    
          システム vimrc: "/etc/vimrc"
          ユーザー vimrc: "$HOME/.vimrc"
       第2ユーザー vimrc: "~/.vim/vimrc"
           ユーザー exrc: "$HOME/.exrc"
      デフォルトファイル: "$VIMRUNTIME/defaults.vim"
           省略時の $VIM: "/usr/share/vim"
    コンパイル: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -D_FORTIFY_SOURCE=2  -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
    リンク: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lelf -lnsl    -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.30/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm     
    
[/code]


CC BY-SA 4.0
2019-09-03T04:19:48.733
57790
2019-09-03T04:19:48.733
35654
57711
answer