views:

1252

answers:

9

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.

+8  A: 

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
system PAUSE
Vim also has support for cscope, which will let you do things like find what functions call a given function - see `:help cscope` for information. There's a nice feature list in the introduction (under "It is designed to answer questions like").
Jefromi
Unfortunately, cscope has a very limited understanding of C++.
Luc Hermitte
+4  A: 

I use a combination of NERDTree (directory sidebar), FuzzyFinder Textmate (go-to-file like TextMate's CMD+T), and Sessions (:h sessions) to help me deal with large projects.

I would suggest using some sessions helper plugin. I would mention what I use, but I'm not satisfied with it yet. Just Google "vim sessions".

One thing to note with getting FuzzyFinder Textmate to work is that it depends on an old version the FuzzyFinder plugin, specifically v2.16. Anything higher and you'll get errors. But it's definitely worth the trouble. While it doesn't have name completion, its search is smart so if I search for fro/time/actionsphp it will pull up the file apps/(fro)ntend/modules/(time)_tracking/actions/(actions).class.(php) (parenthesis denote what it's matching). It makes it very easy to pick out files that are only unique by their folder name.

donut
+1  A: 

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.

Brandon Thomson
I looked into it some more, fuzzyfinder looks like a great idea for project search.
Brandon Thomson
+1  A: 

I'm using two plugins of mine:

  • searchInRuntime that completes filenames on command line. It is somehow similar to fuzzyfinder and lookupfile,
  • lh-tags which is completely experimental and undocumented. It offers two features: automatic and quick update of the tagfile on file save(ing?), and a tag selector plugged to <c-w><m-down> by default. You may want to check the renowned taglist plugin instead.

Both require my viml library lh-vim-lib.

Luc Hermitte
+2  A: 

As well as the invaluable ctags and the various associated commands. I also couldn't live without the project plugin, which allows you to have the files of interest associated with a project in a separate pane. I can't remember how much of my setup is customised, but if I want to open a source file called Debug.c, I hit:

<F12>     " Opens the project pane
/De       " Searches for "De", which is likely to be enough to find Debug.c or possibly Debug.h
<ENTER>   " Opens the selected file and closes the project pane

I often then do:

:vsp      " Vertically split the window
<F12>     " Reopen project pane
#         " Search back to find previous entry with the same name (to find
            Debug.h if I was on Debug.c: my headers are in Headers/ and
            my source is in Source/, so the headers come earlier in the list
            than the source).  I use * to go the other way, obviously.
<ENTER>   " Open the header file in the other window and close the project window.

With this relatively short sequence, I can open any file and it's header in a vertical split. Since the project plugin window is just a text file, completion is achieved by using Vim's searching capability.

Al
+1  A: 

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
Peter Gibson
A: 

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.

Mykola Golubyev
Is it good for C++ code, cscope doesnt work properly for C++
Yogesh Arora
A: 

I use FindFile. If you open vim at the root of your project and run :FC . the plugin will cache all the filenames beneath your cwd. You can then do :FF to open a completion menu and type the name of the file you want (or rather, the first few letters).

Cynshard
+1  A: 

Exuberant ctags.

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

Shin