When in Vim insert mode, is there a way to add filepath autocompletion?

后端 未结 4 1429
挽巷
挽巷 2021-01-29 21:53

I write a lot of shell scripts and I am constantly having to enter in filepaths. I am wondering if anyone knows of a way to get Vim to autocomplete filepaths while in insert mod

相关标签:
4条回答
  • 2021-01-29 22:15

    There's ctrl-x ctrl-f

    :he compl-filename

    0 讨论(0)
  • 2021-01-29 22:17

    I experienced similar problem. I found solution like:

        sudo apt-get install realpath
    

    And in VIM naviagte to file with in normal mode type:

        :r !realpath /path/to/file
    

    When you are navigating in non-insert mode after !realpatch you are able to use our key button.

    VOILA! TAB is working again!

    0 讨论(0)
  • 2021-01-29 22:27

    To build on @CMS and @michael excellent answers

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

    In addition, if you are not already at the file/directory you would like to insert, you can go down a file tree structure as follows:

    1. Optionally enter some part of the directory. You can even use ../../ for example!
    2. Press ctrl+X ctrl+f and select the first item in the tree from the list.
    3. Next press ctrl+f again while the correct item is highlighted to display a list of the next level down the directory tree structure.

    You can keep doing this until you find the directory/file you would like to insert in the document.

    0 讨论(0)
  • 2021-01-29 22:42

    For file name omni completion, you can use:

    Ctrl-XCtrl-F

    0 讨论(0)
提交回复
热议问题