When in Vim insert mode, is there a way to add autocomplete to the file path?

I write a lot of shell scripts, and I constantly have to enter files in the path. I am wondering if anyone knows how to make Vim autocomplete file paths in insert mode, just like when you are in your favorite shell, you insert a tab to complete the path to a directory or file.

Extra credit if you can get CTRL D shell functionality in Vim insert mode (i.e. see which files / directories are in the current path).

+58
vim shell autocomplete text-editor
Dec 17 '09 at 4:36
source share
4 answers

For omni file name completion, you can use:

Ctrl - X Ctrl - F

+118
Dec 17 '09 at 4:42
source share

There ctrl - x ctrl - f

:he compl-filename

+16
Dec 17 '09 at 4:41
source share

Set up great answers on @CMS and @michael

When using the command sequence ctrl + X ctrl + f, it will display a list of files in the current directory. I spend a minute looking for a suitable key to move up and down between different file names. The correct keys are Ctrl-n and Ctrl-p. You can use almost any other key (for example, Space ) to select and continue entering.

In addition, if you are not already in the directory / directory you want to insert, you can go down the structure of the file tree as follows:

  • Enter a part of the directory if necessary. You can even use ../../ for example!
  • Press ctrl + X ctrl + f and select the first item in the tree from the list.
  • Then press ctrl + f again when the correct item is highlighted to display a list of the next level down the directory tree structure.

You can continue to do this until you find the directory / file that you want to insert into the document.

+14
Nov 02 '13 at 13:53
source share

I had a similar problem. I found a solution like:

  sudo apt-get install realpath 

And in VIM naviagte for recording in normal mode:

  :r !realpath /path/to/file 

When you switch to non-insert mode after! realpatch, you can use our button.

VOILA! TAB is working again!

0
Dec 15 '15 at 13:57
source share



All Articles