6

I mostly work on website and sometimes I need to have 3 or 4 buffers displayed for backend and 3 or 4 buffers for frontend at the same time. Tabs are here for that but buffers are mixed. I know I'm a bit fussy but is there a way create buffers "collections" from tab ? It could limit number of opened buffers by tab and be easier to switch from one (buffer) to another.

Spope
  • 481
  • 5
  • 22
  • 1
    personally I feel buffers + splits are much more comfortable (with some plugin, i.e. ctrlp or fussyfinder) than tab... I rarely open files in tab. Maybe I didn't learn the power of tab.... – Kent Oct 14 '14 at 16:10
  • Possible duplicate: [Using Vim's tabs like buffers](http://stackoverflow.com/questions/102384/) (along several other questions on the "Related" column on the right) – mMontu Oct 14 '14 at 16:18
  • I agree with Kent on not using tabs. Here are some tips on how to use [buffers effectively](http://stackoverflow.com/a/21338192/438329) (note this is about closing tabs, but the topic is relevant) – Peter Rincker Oct 14 '14 at 17:04
  • I agree with you, my question is not really clear. I use buffer and splited windows, but I like to use tabs to make a distinction between buffers, a tab with splited buffers for frontend, another tab with splited windows for backend. Like that I wil not mix up files – Spope Oct 14 '14 at 20:42
  • Have you thought about something like separate instances of vim in different tmux windows? – Fred Nurk Oct 15 '14 at 07:04
  • Yes that could be the solution if nothing else can do that in a single vim instance. To be honest I use gvim on windows so I still open 2 gvim, which is not really convenient. – Spope Oct 16 '14 at 08:36

3 Answers3

3

I use tabs quite extensively to work on different directories (sometimes 4+ tabs)

Combining a plugin like CtrlP and the :lcd command you can effectively have multiple workspaces (each with a different directory) with minimal mental upkeep.

The :lcd command changes the directory for the current window only, so the way I use it is as follows.

  1. Open a new tab with :tabnew
  2. :lcd ~/somewhere/else
  3. ctrl + p (default binding for CtrlP to open files in current directory) and find the file you want to edit
  4. switch between tabs using :tn and :tp (obviously I have keybindings for these since I do a lot of switching)

So basically each tab will have it's own working directory, and you use ctrl + p to switch between files/buffers.

Jacob Wang
  • 4,411
  • 5
  • 29
  • 43
  • Yep it's the same use that I have, but buffers are shared between tabs, and this is what I want to avoid if it's possible – Spope Oct 16 '14 at 08:30
  • May I ask why sharing buffers is a concern for you? If you're only opening files using `ctrlP` then you should only be able to access files within that "workspace" right? Are you using `bufdo` extensively? (Sorry I didn't quite answer your original question) – Jacob Wang Oct 16 '14 at 09:35
  • 1
    I use vim with nerdtree to open files and lycosaexplorer to navigate through buffers, and in the same projects I can open many buffers. Split this buffers list with tabs would be more comfortable when I search a specific buffer : I open a tab for js files, a tab for php files, but when I search an opened buffer in my js tab, I see all the php buffers and I don't want to see them. – Spope Oct 22 '14 at 09:08
2

Yes, you can have window-local argument lists:

$ vim
:arglocal foo bar baz
:tabnew
:arglocal arthur robert charles

Now, :args in the first tab page should output:

[foo] bar baz

and, in the second tab page:

[arthur] robert charles

One potential problem with this approach is that you are somehow restrained to argument-specific commands:

:n[ext]
:prev[ious]  (or :N[ext])
:fir[st]     (or :rew[ind])
:la[st]
:argl[ocal]

and tab-specific commands:

:tabn[ext]                         (or gt)
:tabp[revious]  (or :tabN[ext])    (or gT)
:tabfir[st]     (or :tabr[ewind])
:tabl[ast]

which are not as flexible as the more generic commands available if you only use a global argument list (:b <tab>, the cycling nature of :bn/:bp…).

That said, you still have the possibility to look for a plugin on vim.org.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • I've tried to open buffer in tabs with :arglocal myfile.ext but buffer are still shared between tabs – Spope Oct 16 '14 at 08:33
  • The local argument list is passed over to new windows. Creating a new tab with `:tabnew` and then use `:arglocal` to populate the argument list of the new default window is the way to go. – romainl Oct 16 '14 at 09:27
0

I'm using: vim + tmux window / session, for tow frontend and backend dir. else you should use @romainl answer with some limit or create your own plugin.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '21 at 10:40