Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create 2 tab in VIM with separate buffers?

Tags:

vim

tabs

buffer

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.

like image 911
Spope Avatar asked Oct 14 '14 15:10

Spope


2 Answers

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.

like image 130
Jacob Wang Avatar answered Oct 24 '22 04:10

Jacob Wang


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.

like image 26
romainl Avatar answered Oct 24 '22 03:10

romainl