How to navigate in large project in VIM

后端 未结 12 2443
温柔的废话
温柔的废话 2020-12-12 10:19

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 wa
相关标签:
12条回答
  • 2020-12-12 10:31

    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.

    0 讨论(0)
  • 2020-12-12 10:32

    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.

    0 讨论(0)
  • 2020-12-12 10:33

    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
    
    0 讨论(0)
  • 2020-12-12 10:35

    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.

    0 讨论(0)
  • 2020-12-12 10:39

    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.

    0 讨论(0)
  • 2020-12-12 10:39

    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 with gf 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.

    0 讨论(0)
提交回复
热议问题