How to navigate in large project in VIM

2020-02-07 14:22发布

How do you manage big projects (hundreds of files) using only VIM?

I personally start having problems in any larger than small project.

  • is there any way to quickly 'go to file', preferably with name completition?
  • same for 'go to class definition', when it is in another file

I kinda know all the VIM basics, so I don't have problem using it for writing scripts or quick editing some source code. But it gets really messy for me when I have to navigate between files.

标签: vim editor
12条回答
该账号已被封号
2楼-- · 2020-02-07 14:25

VIM has excellent support for tags. Once you have created a tags file for your project, you can jump to a definition or declaration of a method, class, etc., including jumping across files, all inside the same editing session.

Try

:help tags

To generate a tags file for C/C++, go to your shell prompt (I'm assuming your system is *nix/Cygwin) and type

info ctags

or

ctags --help
查看更多
贼婆χ
3楼-- · 2020-02-07 14:30

If you are using ctags as other posters have recommended, then make sure you look at the taglist plugin.

Make sure you take the time to read the docs and learn the key bindings. Here are a few to get you started (from the TList window):

  • o - open file in new window
  • t - open file in new tab
  • [[ or backspace - previous file in list
  • ]] or tab - next file in list
查看更多
趁早两清
4楼-- · 2020-02-07 14:30

Although I'm kinda hoping someone will point out a better solution so I can learn something, NERDTree has been good to me for getting to specific files with name completion as long as I have the tree expanded. The command when I need to get to a file is something like:

,d/foo.pyo (where foo.py is a file name)

,d to open the tree, / to enter search mode, the name (or partial name, or regex, or whatever) of the file, and then o to open.

Of course you may have to hit 'n' a few times if you didn't type enough of the filename or there are duplicates.

I admit it feels like a bit of a hack using NERDTree like this although it has gotten so far into my muscle memory by now that I don't even think about it.

Of course I use ctags too but those are only useful when you have a function near the cursor and need to get to its definition in another file or something. A lot of times I say "OK, I need to work on feature x now" and need to navigate to another file without any references nearby that ctags would really help with.

查看更多
淡お忘
5楼-- · 2020-02-07 14:30

Try SourceCodeObedinece. This one I developed to handle C++ 1Gb source files project.
I use it in pair with 0scan.

These two plugins are wrappers around the most popular Vim browsing tools: ctags and cscope.

查看更多
Rolldiameter
6楼-- · 2020-02-07 14:31

Exuberant ctags.

Use Ctrl-] to jump to the tag under the cursor.

查看更多
何必那么认真
7楼-- · 2020-02-07 14:35

I like simple solutions, my favorite way to navigate at the moment is:

Add to ~/.vimrc.local

set path=$PWD/**

Then type this in the editor to find the file anywhere in the current working directory (pwd)

:find user_spec.rb

You can use tab-completion on the filenames to find multiple choices as well, making this TextMate convert very happy.

查看更多
登录 后发表回答