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.
Opening
vim
from root of your source file and extendingpath
option to include all sub-directories therein.For example
set path+=/usr/include/c++/**
for C++ headers andset path+=**
for your source directory.This ,then, opens a plethora of following possibilities.
1) Opening file by name or parts of it
You can use auto-completion and wildcard expansion with
:find
reliably. You type the name, it will locate the name. This works language agnostic.I am sure you will like it.2) Navigating to files under cusror:
if you want to go a file path like
#include "project/path/classA.h
.Ctrl-6 - to come back to last cursor position after
gf
orgF
3) API lookup and navigating to the API location
[i
or[I
can be used to look up your function signature for word under cursor without leaving your workspace.[<Tab>
to actually go to declaration. Use Ctrl-6 to come back to last location.Without extending
path
, you can start navigating files by:Ex
command and navigate and open your file. I preferNerdTree
over this though.Starting in Vim 7.3, the
:find
command has tab-completion of filenames.So if you set your
'path'
option to contain your entire project (probably using the**
wildcard to allow recursively searching subdirectories), then you can use the:find
,:sfind
,:tabfind
, etc. commands with completion to get to any file in your project. This also allows jumping to files directly withgf
and friends if the file name is in your text, for example in an include directive.With this method, no external tools or plugins are needed for navigating to specific files. Although, it may admittedly not be as fast or easy to use, and doesn't address the need for jumping to definitions. For definitions, I use ctags as other answers suggest.
I'm using two plugins of mine:
<c-w><m-down>
by default. You may want to check the renowned taglist plugin instead.Both require my viml library lh-vim-lib.
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 fileapps/(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.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).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:
I often then do:
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.