Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow multiple terminals opened in different tabpages #452

Open
Bekaboo opened this issue Jul 1, 2023 · 10 comments
Open

[Feature] Allow multiple terminals opened in different tabpages #452

Bekaboo opened this issue Jul 1, 2023 · 10 comments

Comments

@Bekaboo
Copy link

Bekaboo commented Jul 1, 2023

Hi, thanks for making this awesome plugin, it makes nvim's builtin terminal much more ergonomic and user-friendly.

Sometimes I work on 2+ projects in neovim and keeps them in multiple tabs, and it would be nice to have multiple toggleterms opened in these tabs. Currently if I open a toggleterm in one tab, switch to another tab and call 'toggleterm.toggle_command()` again, toggleterm will close the terminal in the previous tabpage instead of opening a new one in the current tabpage.

I assume this might be a config issue and can be solved by passing proper opts to toggleterm? The following is my config if that's related:

local toggleterm = require('toggleterm')

toggleterm.setup({
  open_mapping = '<C-\\><C-\\>',
  shade_terminals = false,
  start_in_insert = false,
  hide_numbers = true,
  autochdir = false,
  persist_size = false,
  direction = 'horizontal',
  float_opts = {
    border = 'shadow',
    width = function()
      return math.floor(vim.go.columns * 0.7)
    end,
    height = function()
      return math.floor(vim.go.lines * 0.7)
    end,
    winblend = 0,
  },
  size = function(term)
    if term.direction == 'horizontal' then
      return vim.go.lines * 0.3
    elseif term.direction == 'vertical' then
      return vim.go.columns * 0.35
    end
  end,
  highlights = {
    NormalFloat = { link = 'NormalFloat' },
    FloatBorder = { link = 'FloatBorder' },
    WinBarActive = { link = 'WinBar' },
    WinBarInactive = { link = 'WinBarNC' },
    MatchParen = { link = 'None' },
  },
  winbar = {
    enabled = false,
  },
  on_open = function()
    vim.cmd('silent! normal! 0')
  end,
})
@akinsho
Copy link
Owner

akinsho commented Jul 3, 2023

Hi @Bekaboo,

Tab scoped terminals is definitely something that has come up before and is an interesting idea. There are definitely some things to iron out about how it would work though. The simplest solution is that if you set some value on the terminal itself and if true then toggleterm treats it as only existing in the tab it was created in and if false it opens wherever.

I worry about introducing all of this complexity though as one of the first things I imagine this will introduce is a bunch of feature requests to accomodate a bunch of minutiae. I tend to lean more towards keeping the plugin as simple as possible to reduce the maintenance burden in the long run.

TLDR: seems like a cool idea, not clear on all the specifics of how it would work. Don't currently have the time to build it and I'm worried it will lead to more complexity.

@Bekaboo
Copy link
Author

Bekaboo commented Jul 3, 2023

OK, thanks for your response. should I close this issue?

@akinsho
Copy link
Owner

akinsho commented Jul 3, 2023

@Bekaboo no we can leave it open, someone might decide to pitch in since it's a popular idea I've heard before. If not maybe when things calm down at work I'll take a look at it.

@sleewoo

This comment was marked as duplicate.

@coot

This comment was marked as duplicate.

@akinsho
Copy link
Owner

akinsho commented Oct 18, 2023

It's fine to want things but if no one else is willing to put the time or effort in or contribute since this is OSS it won't get done. For better or worse I have a life and a job and this isn't a priority for me over those. Please no more plus one comments.

@akinsho
Copy link
Owner

akinsho commented Oct 18, 2023

Relates #500

@anurag3301
Copy link

I was also recommending an easy way to split the terminal and have more. Like in below example I tried splitting it with <C-W>v
image
It does seem like we have tow terminals, but they are just copied, If I write to one, it appears on the second to. Feels like could be a nice features.
image

@tarunaksha
Copy link

tarunaksha commented Jan 28, 2024

I have a solution here....you can check....In my case each terminal is working fine >> #533 (comment)

@axelhj
Copy link

axelhj commented Apr 7, 2024

Hi @Bekaboo!

I have a related issue but I don't feel it is a bug. In the same situation as OP reports I've found that when a toggle-term terminal is currently opened in another tab, then Neovim will switch to that tab if i run :ToggleTerm to close that terminal which is opened in the other tab. I observed it with a minimal Neovim config.

How I hande it to not lose context (my current tab number) is that I use a condition in my keymap;

  local should_restore_mark = require "toggleterm.ui".find_open_windows() and
    vim.o.buftype ~= "terminal"

and based on it I set a global mark and restore it after :ToggleTerm was called. It enables my current workflow. I guess Jumplist navigation could be used instead. I invoke the toggleterm mapping twice to "move" my active terminals into my current tab.

I know OP would like to get separate terminals in the new tab - basically I have another little "hack" for that; call :ToggleTermToggleAll if find_open_windows() gives true before using eg. :ToggleTerm2 if the old terminal had term-number 1, to get a fresh terminal in the separate tab while keeping the old terminal as a hidden buffer. Combined with the above few commands and a some bookkeeping with autocommands around TabNew & TabEnter could make ToggleTerm behave as if there were a separate session in each tab.

I feel that this described autocommand setup could be added as an optional feature into ToggleTerm itself but maybe it is to contrived of an implementation. I guess each terminal buffer should have some meta-data to say which tab they belong to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants