5

I am in vim in the .gitignore file. I now want to add a file path that already exists on the current dir, e.g.

./app/poit/narf/auth.json

I don't want to type it though, I want to navigate to that file somehow with tabcompletion in vim and then insert its filename in the .gitignore file.

How can I achieve this?

What I know I can do is open the editor command

:e app/poit/narf/auth.json

and I can have tabcompletion here. Yet this only gets me the text in the command window, and now I have to yank it somehow inside the buffer. I am also looking more for a more fit solution.

7

You can use vim's file name completion feature for this. To use it, press CTRL-xCTRL-f in insert mode. For more on this, see :help compl-filename. Do note that it isn't recursive, so you must complete the path level by level. (first app/, then poit/, etc.)

  • I see a box opening, yet I am unsure how to navigate within it. Ctrl+N and Ctrl+P move up and down, yet I do not understand your "it isn't recursive part". Could you please elaborate on how I can complete a nested file name multiple level down? – k0pernikus Jan 8 '16 at 11:00
  • To select items from the list, use the Ctrl+N and Ctrl+P keys, and keep typing to finish the completion. What I mean by it being non recursive is that you have to complete the path each item at a time, like you would with tab completion in a bash shell. – EvergreenTree Jan 8 '16 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.