How do you work with large projects in VIM
Asked Answered
R

4

6

I have large projects with many levels of folders. Some files are named the same and depending on the folder name their function vary. For example

/admin/action1.php
/action1.php

First one would refer to administrative tasks and second one would be accessed by users. Vim gets cluttered with tabs and buffers very quickly and its getting hard to move around. Pluigins I'm using are: NERDTree CtrlP MiniBuffExplorer

I'm using gVim for Windows and plugins like YouCompleteMe are not an option.

  • NerdTree - is too clumsy to move around back and forth between folders on large projects
  • CtrlP - you have to know what you're looking for by typing names all the time
  • MiniBuffExplorer - have ridicculus amount of files, takes way to much space on screen and its impossible to find anything
  • Vim-Session - Open Save tab/windows for project

enter image description here

As you can see on the picture there are way to many tabs to remember witch tab correspond to witch part of the code. MiniBuffExplorer isn't helping too much.

So my question is how would you go about working with large project in VIM to keep things organized preferably by their function or section of the code. Is there a clean way to do it? Is there a way to group buffers or tabs like:

Migrations
Seeds
Admin Controllers
Admin Views
Config
Roscoeroscommon answered 26/9, 2013 at 14:3 Comment(7)
possible duplicate of Howto organize Vim buffers, windows and tabs when working with many filesCrusado
... see also How to navigate in large project in VIM (and many other similar questions).Crusado
You're right it's a common problem. I was trying to show my setup with specific plugins and how it looks on my project. Hoping that maybe I need to use different plugin, configure plugins I already have differently or find pointers on how the workflow should look like.Roscoeroscommon
It looks to me like you may also benefit from re-evaluating your workflow. Unless you are performing a very specific bulk action, the odds that you need to keep 100+ buffers open at one time are probably very low. I have gotten into the habit of using :bd to close an open buffer, instead of :q, because if I'm done with the file for now, I want it to go away.Excreta
I use Unite.vim to open files which behaves very similarly to CtrlP. Fuzzy file matching makes it very easy to open the right file. Combine this with some liberal use of a grep-like tool to find which file has the thing you want, and you can get to the right file mighty quickly.Excreta
Thanks for a hint with :bd I was always <ctrl>wq windows and that kept the buffers hanging. I will give plugin Unite a tryRoscoeroscommon
Also try using :CtrlPBuffer, I find it very useful to be able CtrlP among opened buffersAli
H
6

I don't think the tools are at fault, here. It's more how you use them.

  1. Tabs are not designed at all as file proxies like they are in others editors. Tabs are workspaces, allowing you to organize windows how you like them. They are the best candidates for your

    Migrations
    Seeds
    ...
    

    scenario.

    Here is one possible way to create a "Migration" tab:

    :tabnew | lcd path/to/Migration
    

    From there, all the windows you create in that tab will inherit the Migration working directory and every :e, :sp, :vs or even :vim will start from that working directory.

    Also, this will make NERDTree and netrw show the content of your local working directory by default.

    See :help seeting-tabline and :help setting-guitablabel if you want to change the name of the tab.

  2. You should use CtrlP's path mode to do the matching on the whole path rather than the filename:

    fbruse
    

    would match:

    foo/bar/user
    

    but not:

    baz/vroom/user
    

    With the tab setup above, CtrlP's suggestions should be restrained to the Migration directory, making it a lot faster.

    CtrlP is not perfect though: it can be slow in large projects so make sure you read the whole documentation.

  3. An "always on" list of open buffers may be a good idea when you have a small number of them but, like tabs, it obviously doesn't scale at all. It is vastly better to show the list when you actually want to switch buffers: less screen estate and brain cells wasted!

  4. Be aware, though, that while it is possible to define a window-local argument list, there's AFAIK no way to define a window-local buffer list. Since the argument list always leaks into the buffer list and the buffer list is global, buffer commands will always deal with the same quantity of buffers, no matter what tab you are in. Thus limiting the general usefulness of tabs.

  5. Files are not a very good metaphor for dealing with large projects: you must keep a complex symbol->file map in your head while your program is made of functions, classes, arrays, variables… not files.

    Using tags (:help tags) is a very convenient way to jump around your project:

    :tag foo
    :tag bar<Tab>
    :ptag /baz<Tab>
    

    And CtrlP's :CtrlPTags makes it almost fun.

FWIW, tag-jumping is my favorite navigation technique and I usually don't use tabs or windows.

Harrumph answered 26/9, 2013 at 15:58 Comment(2)
1. This is exactly how I use tabs for. I'm using vim-session plugin and changing Tab name is not being saved. When I restore session its all gone. I like your idea of CtrlPTags and I will try to implement it instead using purely files as a reference,Roscoeroscommon
NerdTree has a bookmark feature, so you can mark your main folders and access these quickly. You can configure your nerdtree to always show the bookmark list with this line let NERDTreeShowBookmarks=1Fresh
O
2

You may want to take a look Vim-CtrlSpace, it is quite suitable to work on large projects. This plugin helps you deal with tabs, buffers, sessions, and more.

You can check the new demo video on YouTube.

Ocko answered 6/5, 2014 at 21:39 Comment(0)
H
0

I'm using gVim for Windows and plugins like YouCompleteMe are not an option.

This statement is false. Checkout my other answer on this particular topic.

Good luck.

Handfasting answered 2/10, 2013 at 11:23 Comment(3)
I tried YouCompleteMe before and I couldnt get it to work. On my Mac it runs fantastic dough. I worked on it all morning today. I tried your version of vim and your compiled YCM plugin and all I'm getting is "YouCompleteMe unavailable: ycm_core too old, PLEASE RECOMPILE ycm_core" when I start Vim.Roscoeroscommon
You are obviously doing something wrong. Are you sure that you have libclang.dll in the PATH environment variable?Handfasting
In addition, read the Common Pitfalls section in my other answer.Handfasting
M
-1

Vim is not an IDE; it looks to me like you're pushing the limits of what makes sense (to open concurrently) in Vim. You can easily set up simple integrations that allow you to open a file in Vim from an IDE.

I'd suggest you use each tool where it's best: The IDE for managing and navigating through large projects, and Vim for its superior text editing capabilities!

Macrogamete answered 26/9, 2013 at 14:57 Comment(1)
Im aware that VIM in not an IDE. I can do everything I want in VIM except organizing my workflow so I can easily jump to the file I need at the moment.Roscoeroscommon

© 2022 - 2024 — McMap. All rights reserved.