akinsho / toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
GNU General Public License v3.0
4.38k stars 176 forks source link

Cannot open multiple terminals while in terminal mode #533

Open ivanovaleksandar opened 9 months ago

ivanovaleksandar commented 9 months ago

Current Behavior

The current setup allow me to spawn multiple terminals, just like expected, meaning that 1<c-t> and 2<c-t> opens terminal 1 and 2 respectively. The current issue is that doing 1<c-t> and then 2<c-t>, the terminal does not split in two, but instead closes the terminal, same as doing <c-t>.

Is I do this with command :ToggleTerm 1 and :ToggleTerm 2 it works like expected.

Expected Behavior

The expected behaviour is that spawning a second terminal, the screen will split the screen of the first terminal and open the second one.

Steps To Reproduce

Using lazyvim with lunarvim, this is the current relevant config:

lvim.keys.normal_mode["<c-t>"] = false
lvim.builtin.terminal.open_mapping = "<c-t>"
lvim.builtin.terminal.active = true

  {
    "akinsho/toggleterm.nvim",
    config = function()
      require("toggleterm").setup({
        open_mapping = [[<c-t>]],
        terminal_mappings = true,
        direction = "horizontal",
        size = 30,
      })
    end
  }

Environment

- OS: MacOS Sonoma 14.1.1 (23B81)
- neovim version: 0.9.0
- Shell: zsh

Anything else?

No response

tarunaksha commented 9 months ago

So I wanted to get the results as shown here:

toggletermgif

I looked for this configuration in several platforms like reddit,youtube,stackexchange etc. but didn't find the proper solution. After brainstorming(as I am new to vim) for hours I finally figured it for my usecase.

i am using lazy-vim currently.

Here are my setups to achieve this...

init.lua

require("config.lazy")

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    "akinsho/toggleterm.nvim",
    config = function()
      require("toggleterm").setup()
    end,
  },
})

lua/plugins/toggleterm.lua

return {
  "akinsho/toggleterm.nvim",
  version = "*",
  config = true,
  opts = {
    size = 12,
    open_mapping = [[<c-\>]],
    shade_filetypes = {},
    shade_terminals = true,
    shading_factor = 1,
    start_in_insert = true,
    persist_size = true,
    close_on_exit = true,
    direction = "horizontal",
  },
}

Pretty straight-forward and default setup. I use ctrl+\ for opening the terminal horizontally and open another terminal by pressing 2+ctrl+\. For 3rd 3+.... and so on (who needs more than 3). To hide them press ctrl+\ again. To exit them simply type "exit". For giving input in terminal press "i" and press "esc" two times to revert to normal mode. Switching between them is also similar like normal vim mode.

Here is my result: Screenshot from 2024-01-28 18-14-36

blurskye commented 8 months ago

i would highly recomend using something like tmux or a alternative to it for terminal multiplexing....

SublimeIbanez commented 7 months ago

It doesn't open in terminal mode, but here's my lazy config for this: image

While you have to press <Esc> in terminal mode, it gives access to <leader>tt (or whatever you want to set it as) for creating new terminals and <leader>te for exiting them. Also gives you <c-\> for toggling horizontal windows and <c-]> for floating ones.