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.
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
I don't think the tools are at fault, here. It's more how you use them.
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.
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.
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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With