2

Let's say I have my directory/file tree as follows:

/
|_home
  |_myPC
    |_script.sh
    |_test.sh
|_etc
  |_log.txt

I'm working on script.sh and Vim has nothing like firejail to stop it from accessing stuff.

So far, I'm able to, with ctrlp, auto-complete with stuff already in script.sh. However, when I type cat ~/t and use <C-p> (with ctrlp), I want it to auto-complete to cat ~/test.sh or offer that. However, ctrlp alone only seems to access stuff already in script.sh.

How can I make Vim auto-complete with the system file tree? Is there a plugin for that?

3

You can use <C-x><C-f> to enter filename completion.

Vim will understand the partial path already typed and offer you suggestions from paths in the filesystem. You can use the usual <C-p> and <C-n> to navigate the completion menu, also <C-f> works the same as <C-n> in this specific menu.

If you pick a directory name, you can use an additional <C-x><C-f> to start completing the next path component, and so on.

You can use <C-y> to accept the current entry and leave completion, or <C-e> to cancel it.

You don't actually need any plug-ins, this is all a built-in feature of Vim.

See :help compl-filename for filename completion in specific, though you might want to have a look at the whole :help ins-completion for a more complete overview of insert mode completion in Vim.

| improve this answer | |

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.