How to navigate a large project in VIM

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

I personally have problems in any major project.

  • Is there a way to quickly jump to a file, preferably with the completion of the name?
  • same for "go to class definition" when it is in another file

I know all the basics of VIM, so I have no problem using it to write scripts or quickly edit some source code. But I get really dirty when I have to move between files.

+84
vim editor
Sep 22 '09 at 0:15
source share
12 answers

VIM tagging is excellent . Having created a tag file for your project, you can proceed to the definition or declaration of a method, class, etc., including transitions between files, all inside one editing session.

Try

:help tags 

To create a tag file for C / C ++, go to the shell prompt (I assume your system is nix / Cygwin) and type

 info ctags 

or

 ctags --help 
+32
Sep 22 '09 at 0:21
source share

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

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 the padding tab in the file names to find several options, which makes this TextMate converter very happy.

+26
Sep 12 '11 at 12:21
source share

I use a combination of NERDTree (sidebar), FuzzyFinder Textmate (as a file, such as TextMate CMD + T), and sessions (: h sessions) to help me deal with large projects.

I would suggest using an additional session helper. I would mention what I use, but not yet satisfied. Just google "vim sessions".

It should be noted that when working with FutzyFinder Textmate it depends on the old version of the FuzzyFinder plugin, in particular v2.16. All the above and you will get errors. But it's definitely worth it. Although it doesn't have a name, its search is smart, so if I search fro/time/actionsphp , it will pull the apps/(fro)ntend/modules/(time)_tracking/actions/(actions).class.(php) file (brackets indicate that it matches). This makes it easy to select files that are unique only by the name of their folder.

+13
Sep 22 '09 at 0:35
source share

As well as priceless ctags and various related commands. I also could not live without a project plugin , which allows you to have files associated with the project in a separate panel. I can’t remember what part of my setup is configured, but if I want to open the source Debug.c file, 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 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. 

In this relatively short sequence, I can open any file and its title in vertical section. Since the project plugin window is just a text file, completion is done using the Vim search feature.

+7
Sep 22 '09 at 10:24
source share

Starting with Vim 7.3, the :find has a tab filling in file names.

So, if you set your 'path' to the 'path' parameter (possibly using the wildcard ** to allow recursive search subdirectories), you can use :find :sfind , etc. commands with completion to go to any file in your project. It also allows you to jump to files directly with gf and friends if the file name is in your text, for example, in the include directive.

Using this method, external tools or plugins are not needed to navigate to specific files. Although, admittedly, it cannot be so quick or easy to use and does not require the need to jump into definitions. For definitions, I use ctags as other answers suggest.

+4
Aug 19 '13 at 22:10
source share

If you use ctags, as other posters have recommended, be sure to check out the taglist plugin.

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

  • o - open the file in a new window
  • t - open file in a new tab
  • [[or backspace - previous file in the list
  • ]] or tab - the next file in the list
+3
Sep 22 '09 at 11:04
source share

Exuberant ctags.

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

+3
Sep 24 '09 at 15:21
source share

I am using FindFile . If you open vim at the root of your project and run :FC . , the plugin will cache all the file names under your cwd. Then you can do :FF to open the completion menu and enter the name of the file you want (or rather, the first few letters).

+2
Sep 24 '09 at 15:14
source share

Although I really hope that someone will point out the best solution so that I can learn something, NERDTree is well suited for me to receive specific files with the completion of the name, as long as I have a tree. The command, when I need to get the file, looks something like this:

d / foo.pyo (where foo.py is the name of the file)

d to open the tree, / to enter the search mode, the name (or partial name, or regular expression or something else) of this file, and then o to open.

Of course, you may need to press "n" several times if you have not typed enough file name or duplicates.

I admit that it seems like a hack using NERDTree like this, although so far it has reached my muscle memory that I don’t even think about it.

Of course, I also use ctags, but they are only useful when you have a function next to the cursor and you need to go to its definition in another file or something like that. Many times I say "OK, I need to work with the x function now" and you need to go to another file without any links nearby that ctags really help.

+1
Sep 22 '09 at 1:12
source share

I use two of my plugins:

  • searchInRuntime , which completes the file names on the command line. It is somehow similar to fuzzyfinder and lookupfile,
  • lh-tags , which is completely experimental and undocumented. It offers two functions: automatic and quick update of the tagfile when saving the file (ing?) And a tag selector connected to the <cw><m-down> by default. Instead, you can check out the famous taglist plugin.

Both require my viml lh-vim-lib library.

+1
Sep 22 '09 at 6:21
source share

Opening vim from the root of the source file and expanding the path option to include all subdirectories in it.
For example, set path+=/usr/include/c++/** for C ++ headers and set path+=** for your source directory.

This opens up many possibilities.

1) Opening a file by name or part thereof

 :find file_name 

You can reliably use auto-completion and template expansion with :find . You enter a name, it will find the name. This works regardless of language. I am sure you will like it.

2) Going to files in Cusror:
if you want to specify the path to the file, for example #include "project/path/classA.h .

 gf or gF - go to file under cursor. 

Ctrl - 6 - to return to the last cursor position after gf or gF

3) Search API and move to API location

[i or [I can be used to search for function signatures for a word under the cursor without leaving the workspace. [<Tab> actually go to the declaration. Use Ctrl - 6 to return to last place.




Without extending the path , you can start file navigation with the command :Ex , and also navigate and open your file. I prefer NerdTree though that.

+1
Jan 27 '16 at
source share

Try SourceCodeObedinece . I developed this to work with the source files of C ++ 1Gb source files.
I use it in tandem with 0scan .

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

0
Sep 23 '09 at 19:16
source share



All Articles