开发者

Vim: Simple "jump to file" command?

What's the simplest way to "jump to a file somewhere in my source tree by name"? For example, if I'm working with "libfoo" that contains libfoo/foo/foo.py, I'd like to be able to开发者_如何学C jump to foo.py from anywhere within libfoo/**[0].

Possibly some way to do this with a tags file?

[0]: that is, libfoo/ and its subdirectories.


Add ** is to you comma-separated vim path variable (not system path) and if you're in some parent dir of the project use:

:find foo.py


check out command-t, FuzzyFinder, or FuzzyFinder_Textmate

Personally, I find command-t has the best UI, but FuF_Textmate is best for quickly getting to the right place in very large projects (which is why I use it after trying all 3)

Note that fuzzyfinder_textmate is unmaintained by its origional author, so you may have to poke around the gh network tab to find who has the most up to date branch. also note it is a bit of a pain to install.


You can use Vim's tab completion of filenames in conjuction with the ** recursive directory expansion.

e.g. type: :e libfoo/**/foo.py and hit TAB. This will search down from the libfoo directory to find a file that matches. If there is more than one match you can cycle through them with the TAB key. When you find the one you want press enter to complete the command and edit the file.

For more about the ** matching do :h starstar. It requires a version of Vim compiled with the +path_extra option.

If you have already edited the file once you can also search the buffers for partial name matches with the :b name command. e.g. :b foo.py<TAB> will expand to a buffer name that has 'foo.py' anywhere in it. N.B. it matches the entire path, so :b foo<TAB> would match all buffers with files from the libfoo directory.


ctags --extra=f . creates tags with the same name as files pointing to the first line:

ctags -R --extra=f .

Then you can just do:

:tag file_na

and tab complete away.

Mentioned at: Vim and ctags: tag filenames


ctrlp.vim

Full path fuzzy file, buffer, mru, tag, ... finder for Vim.

  • Written in pure Vimscript for MacVim, gVim and Vim 7.0+.
  • Full support for Vim's regexp as search patterns.
  • Built-in Most Recently Used (MRU) files monitoring.
  • Built-in project's root finder.
  • Open multiple files at once.
  • Create new files and directories.
  • Extensible.

You can find it at https://github.com/ctrlpvim/ctrlp.vim.


check this out:

https://github.com/zhchang/quick_file

unique features: 1. you don't need to know where exactly it is, as long as it is in one of the sub dirs 2. you don't have to remember the full name, fragments will do 3. it will go to most shallow match, but with more fragments of the path supplied, it will match deeper.


map <S-F12> :execute "!start explorer \"" . expand( "%:p:h" ) . "\""<CR>

starts up an explorer window in the directory of the file you are using

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜