8

I’m trying to use vim’s compl-filename feature (Ctrl-XCtrl-F) to complete paths in INSERT mode, but I can’t work out how to traverse into directories without (temporarily) ending the completion mode:

Let’s say I want to complete the path /etc/sysconfig/network-scripts/ifup.

I would like to be able to do something like:

/eCtrl-XCtrl-F
/etc/
/etc/sysCtrl-F
/etc/sysconfig/
/etc/sysconfig/netCtrl-F
/etc/sysconfig/netconsoleCtrl-N
/etc/sysconfig/networkCtrl-N
/etc/sysconfig/network-scripts/
/etc/sysconfig/network-scripts/ifupCtrl-Y
/etc/sysconfig/network-scripts/ifup

The issue is, as soon as I start typing* after a path match (like /etc/), it ends file name completion. I would like it to stay in file name completion, so that I can still use Ctrl-F, Ctrl-N, etc. Since it ends completion, I have to type Ctrl-XCtrl-F again to restart it, and the helpful completion popup menu disappears in the meantime.

Is there an option I can set to change this?

* By ‘typing’ here, I am referring to characters in 'isfname' -- of course, typing other characters (like space or punctuation) should not continue file name completion.

4 Answers 4

5

I'm not sure exactly what you're saying, but you can just press Ctrl-XCtrl-F again on a directory while you're in the completion menu to expand it. You don't have to close out of the menu first. I just keep Ctrl held down and tap xf to traverse a directory, n and p to move up and down and w to go back up.

If you don't use :h i_CTRL-F then you could remap it. For example,

inoremap <C-f> <C-x><C-f>
Sign up to request clarification or add additional context in comments.

4 Comments

If I type ^XF immediately after completing one part of the path (ending with a /), I might have to scroll through many paths to find the one I want, without being able to restrict the options by typing extra characters. ^XFP will at least let me type extra characters, but is clunky and just shouldn't be necessary.
@codebeard You shouldn't ever need to type ^XFP. If you start typing /et then you can hit ^XF. Then type X^XF (for example) to get to /etc/X11/. You can just start typing while you're in the menu without using ^P. It's quite possible I'm biased here, but I can really imagine a better way to do it. You could inoremap <Tab> <C-x><C-f> if you want it to behave like bash completion.
Except that as soon as I type the 'X' here, I lose the popup menu, which is probably the goal of using file name completion in the first place -- I rarely use it to save typing (I can type a 30 character path name in less time than it takes to mess around with key combinations), but I use it when I can't remember what path I was looking for. Also, inoremap <Tab> ... is probably unwise given the importance of the <Tab> key in editing most files.
@codebeard Oops, I meant I can't imagine a better way to do it. There might be a plugin out there that puts you back into file completion mode until you hit <Space> to end it. Hope you find something that works well for you.
2

Simple remap would be

inoremap / /<C-x><C-f>

So when you type slash(/) in insert mode you will get that auto completion popup :)

Place it in your .vimrc file (for vim) or in init.vim (for neovim)

Comments

0

Vim doesn't do auto-completion.

For that, you'll need a dedicated plugin like AutoComplPop or NeoComplCache

Comments

0

Please use insert "i" first before using cntr+x+f. I was in similar situation. :)

1 Comment

? didnt help here. You mean to be in insert-mode?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.