I'd like to use
<C-X> <C-F> to autocomplete a long filename in insert mode, say
/foo/bar/baz.txt. When I type in
/f, I can press
<C-X> <C-F> to complete to
/foo/. However, after typing
/foo/b, I'll need to press
<C-X> <C-F> again to complete to
/foo/bar/. After typing
/foo/bar/b, I'll need to press
<C-X> <C-F> one more time to get to
/foo/bar/baz.txt. Is there any way to keep the completion menu alive inbetween directory slashes
/ for longer filenames?
I'd like to use
(Untested) You'll need a vim that supports
CompleteDonePre. You can check with
echo has('##CompleteDonePre') ? 'supported' : 'not supported'
If you have this event, you can use the following autocommand:
augroup ContinueFileCompletion autocmd! autocmd CompleteDonePre * if complete_info()['mode'] ==# 'files' | call feedkeys("\<C-x>\<C-f>", 'n') | endif augroup END
- You might be able to get away with
normal! <C-x><C-f>instead of
call feedkeys(...); I'm not sure in this case, since we're doing this from an autocommand
- You could modify this to also check if the completed item was a directory. I would probably extract a function at this point and call it in the autocommand, but the check could be something like
let compinfo = complete_info() let compitem = compinfo['items'][compinfo['selected']] " use compitem, which is a dictionary... (:help complete-items)
- This doesn't handle aborted completions; you can check if the dictionary
v:completed_itemis empty for that (I think—the help says "if completion failed", and the event is triggered when "something was completed or abandoning completion").
empty(v:completed_item)would do the trick.
YouCompleteMe plugin does the thing. But it may be overwhelming if you need only file path autocompletion. YCM is not so easy to use, it is python dependant, requires compilation, much space on disk and works with certain file types. To enable it on any file type you have to specify one of acceptable. For example:
Then you just type path in text and it completes on each slash. As bonus you will get fuzzy search.