hrsh7th / cmp-path

nvim-cmp source for path
MIT License
599 stars 55 forks source link

How to select file/dir in Ex mode completion when input is not a prefix? #78

Open TamaMcGlinn opened 2 weeks ago

TamaMcGlinn commented 2 weeks ago

In command-mode, e.g. when you do :e ~/somedir/file but before pressing enter, file completion pops up. I can press tab if I happened to enter the prefix of a valid entry, and it will complete it. For example, if there is a file called file_something.txt then this works. If there are multiple entries, tab again to select the next. But if the file is instead named something_file.txt I can see the completion result, but pressing tab does nothing. How do I select the completion?

Repro steps

  1. touch ~/file_something.txt
  2. nvim -u repro.vim (listed below)
  3. :e ~/som

image

You can see the completion right there, but does nothing, and will edit ~/som.

repro.vim

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  augroup plug_install
    autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  augroup END
endif

" Install vim-plug if not found
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

call plug#begin('~/.vim/plugged')
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-path'
call plug#end()

lua <<EOF
local cmp = require('cmp')
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  sources = cmp.config.sources({{name = 'path'}}, {{name = 'cmdline'}})
})
EOF