Vim insert mode file path completion
I want to change where vim looks for file completion, but only in insert mode. For example:
I open gvim inside of the CG-Website
directory.
This is my directory structure:
Then i go in to the css folder and open style.css
using :e src/static/css/style.css
Now i am inside of style.css and i want to complete a file name that is down one directory.
I want to be able to type ../
in INSERT
mode and have all the files/folders that are inside of the static folder show up, instead of the www
folder which is what it does right now.
However I don't want to change the actual directory, because I still want :e
to work normally.
Insert mode filename completion is always done from the "current directory" or "working directory" which may or may not be the directory of the current file. Since you don't want to change directories, filename completion can't work like you want it to work.
Actually, the last sentence of :h compl-filename
should give you a hint:
Search for the first file name that starts with the
same characters as before the cursor. The matching
file name is inserted in front of the cursor.
Alphabetic characters and characters in 'isfname'
are used to decide which characters are included in
the file name. Note: the 'path' option is not used
here (yet).
One solution to this problem is to set autochdir
so that Vim always changes the working directory to the directory of the current file and use a plugin like CtrlP (there are others) for navigation. When configured properly, CtrlP lets you navigate your files from your project's home as defined by the presence of a .git
or similar directory. This is really handy.
However, you can get around that limitation relatively easily with set autochdir
(again, you need it for filename completion to work like you -- and I -- want it to work) and a bit of creativity:
nnoremap <F9> :e ~/path/to/project/
Consider this mapping as a quick shortcut to your project.
I think you are approaching this the wrong way. You want to filter results relative to your last opened dir without changing your current dir and that doesn't quite make sense.
My recommendation is to use a tool what will allow you to quickly filter through all of your files from the root folder of your project.
Take a look at Command-T: Fast file navigation for VIM
PS: you need vim with ruby support for that.
链接地址: http://www.djcxy.com/p/37638.html上一篇: 用vim中的换行符在光标下打开一个文件
下一篇: Vim插入模式文件路径完成