akinsho / toggleterm.nvim

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

[BUG] Toggleterm does not respond or sometimes blinks when creating a new window #536

Closed Anifyuli closed 7 months ago

Anifyuli commented 7 months ago

Is there an existing issue for this?

Current Behavior

Toggleterm not creating a new window

Expected Behavior

Toggleterm created a new window beside current active session

Steps To Reproduce

  1. Launch Neovim with my configs
  2. Open Toggleterm with F7
  3. Can't create a new Toggleterm window

Environment

- OS: Ubuntu 23.10
- neovim version: 0.9.5
- Shell: Zsh 5.9

Anything else?

This my configs for Toggleterm

...lua/config/keymaps.lua

map("n", "<leader>Th", "<cmd>ToggleTerm size=10 direction=horizontal<cr>", { desc = "ToggleTerm horizontal split" })
map("n", "<leader>Tv", "<cmd>ToggleTerm size=40 direction=vertical<cr>", { desc = "ToggleTerm vertical split" })
map("n", "<leader>Tf", "<cmd>ToggleTerm direction=float<cr>", { desc = "ToggleTerm float" })
map({ "n", "t" }, "<F7>", "<Cmd>ToggleTerm<CR>", { desc = "Show/hide ToggleTerm" })
map({ "n", "t" }, "<C-'>", "<cmd>ToggleTerm<cr>")

-- Remove Toggleterm buffer
map({ "n", "t" }, "<M-.>", function()
  for _, buf in ipairs(vim.api.nvim_list_bufs()) do
    if vim.bo[buf].filetype == "toggleterm" then
      vim.cmd.bdelete({ args = { buf }, bang = true })
    end
  end
end, { desc = "Exit from Toggleterm" })

...lua/plugins/toggleterm.lua

local map = vim.keymap.set

function _G.set_terminal_keymaps()
  local opts = { buffer = 0 }
  map("t", "<M-q>", [[<C-\><C-n>]], opts)
  map("t", "jk", [[<C-\><C-n>]], opts)
  map("t", "<C-h>", [[<Cmd>wincmd h<CR>]], opts)
  map("t", "<C-j>", [[<Cmd>wincmd j<CR>]], opts)
  map("t", "<C-k>", [[<Cmd>wincmd k<CR>]], opts)
  map("t", "<C-l>", [[<Cmd>wincmd l<CR>]], opts)
  map("t", "<C-w>", [[<C-\><C-n><C-w>]], opts)
end

-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")

return {
  "akinsho/toggleterm.nvim",
  cmd = { "ToggleTerm", "TermExec" },
  version = "*",
  opts = {
    highlights = {
      Normal = { link = "Normal" },
      NormalNC = { link = "NormalNC" },
      NormalFloat = { link = "NormalFloat" },
      FloatBorder = { link = "FloatBorder" },
      StatusLine = { link = "StatusLine" },
      StatusLineNC = { link = "StatusLineNC" },
      WinBar = { link = "WinBar" },
      WinBarNC = { link = "WinBarNC" },
    },
    open_mapping = [[<F7>]],
    float_opts = {
      border = "curved",
    },
  },
}

I'm using LazyVim as my distro config. You can check too my LazyVim config here

I attach my recorded screen

https://github.com/akinsho/toggleterm.nvim/assets/73734843/d06cfd82-6fc6-4a52-976b-5539f6905f8a

Sorry if my video have bad resolution, and sorry My English

Anifyuli commented 7 months ago

Solved : open mapping options different with my keybind, so it can't create new terminal window