Khalid Akash
Khalid Akash

Reputation: 197

Is it possible to open a tab inside of a split

I currently have a Vim configuration where I have NERDtree on the left, and a terminal open on the bottom, and my main editor in the top right corner. I would like to open new files in tabs inside the editor split instead of replacing the entire screen with the new file. Is this possible?

Upvotes: 5

Views: 4470

Answers (3)

JDS
JDS

Reputation: 1969

My solution to this problem is to simulate tabs in a split using NERDTreeMirror

Adding this to one's vimrc may achieve a similar effect as an IDE's static browser pane. It mostly works for me:

Plugin 'preservim/nerdtree'
autocmd VimEnter * NERDTree
autocmd BufWinEnter * NERDTreeMirror

The first autocmd starts NERDTree on startup.

The second autocmd will clone the existing NERDTree to any new tab.

So, if you hit t on a node in NERDTree, it will open that node (file, presumably) in a new tabbed window. And also, the NERDTree will be mirrored in a split pane in that new tab

This does basically copy the NERDTree pane to each tab but to a human, the effect is similar to an IDE's static browser pane.

Lately, I've found I don't always want the NERDTree so I removed the first autocmd and will start NERDTree manually if I need it.

Upvotes: 2

pantosaur
pantosaur

Reputation: 96

I think i see the IDE-like workflow you are trying to achieve, and that is totally possible but tabs are not how to do it. Since tabs are a window layout that represent an independent view of your editor space, they can be useful for, let's say have multiple views of the same workflow, for example an editor view and a debugging view or anything you can think of.

What i think we are looking for is to use vim buffers. For example, open Nerdtree, a terminal with :term, and anything that is part of your workflow in a single layout (tab). And then you want to use the editor window (split) to edit multiple buffers.

A very good summary of how to use buffers can be found there: https://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/

Upvotes: 8

D. Ben Knoble
D. Ben Knoble

Reputation: 4673

TL;DR: No

A tab page in vim "holds one or more windows" (:help tab-page-intro). Also known as a collection of windows. Vim is quite powerful with respect to window management, allowing you to create any combination of editing windows you desire, and then create a new tab page to work on something else without destroying your carefully-designed layout.

You cannot have one split act like a tab; instead, you can split that window further, or switch between files using :edit, :find, :Explore, and many other methods.

See for example the article I linked in the comments.

Upvotes: 5

Related Questions