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

[BUG] insert_mappings=false not working #605

Open
1 task done
Dioswilson opened this issue Aug 17, 2024 · 1 comment
Open
1 task done

[BUG] insert_mappings=false not working #605

Dioswilson opened this issue Aug 17, 2024 · 1 comment

Comments

@Dioswilson
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have this configuration:

 config = function()
     require("toggleterm").setup({
         open_mapping = [[<leader>t]],
         start_in_insert = true,
         -- terminal_mappings = true,
         insert_mappings = false, -- whether or not the open mapping applies in insert mode
         direction = "horizontal",
         close_on_exit = true, -- close the terminal window when the process exits
     })
 end,

with leader being spacebar, when hitting spacebar to separate words it keeps waiting for the next key and only option it apears in which key is toggle term

Expected Behavior

insert_mappings=false should prevent me from hitting <leader>t to close the terminal while writing

Steps To Reproduce

  1. Copy plugin configuration
  2. Set spacebar as leader
  3. Open terminal with <leader>t]
  4. Hit spacebar

Environment

- OS: Archlinux 
- neovim version: 10.1 
- Shell: Zsh

Anything else?

No response

@mbwilding
Copy link

mbwilding commented Sep 29, 2024

My fix was removing t mode from my manual mappings. When I leave insert mode in ToggleTerm I can use my bindings.
But if that config above was your total config around ToggleTerm, then this won't help you.

before

vim.keymap.set({ "n", "t" }, "<leader>th", "<cmd>:1ToggleTerm direction=horizontal<CR>")
vim.keymap.set({ "n", "t" }, "<leader>tt", "<cmd>:2ToggleTerm direction=horizontal<CR>")
vim.keymap.set({ "n", "t" }, "<leader>tn", "<cmd>:3ToggleTerm direction=horizontal<CR>")
vim.keymap.set({ "n", "t" }, "<leader>ts", "<cmd>:4ToggleTerm direction=horizontal<CR>")
vim.keymap.set({ "n", "t" }, "<leader>tc", "<cmd>:ToggleTermToggleAll<CR>")

after

vim.keymap.set("n", "<leader>th", "<cmd>:1ToggleTerm direction=horizontal<CR>")
vim.keymap.set("n", "<leader>tt", "<cmd>:2ToggleTerm direction=horizontal<CR>")
vim.keymap.set("n", "<leader>tn", "<cmd>:3ToggleTerm direction=horizontal<CR>")
vim.keymap.set("n", "<leader>ts", "<cmd>:4ToggleTerm direction=horizontal<CR>")
vim.keymap.set("n", "<leader>tc", "<cmd>:ToggleTermToggleAll<CR>")

complete

return {
    "akinsho/nvim-toggleterm.lua",
    opts = {
        auto_scroll = true,
        close_on_exit = true,
        hide_numbers = true,
        insert_mappings = false, -- Relevant
        persist_size = true,
        shade_terminals = false,
        start_in_insert = true,
        terminal_mappings = false, --  Relevant
    },
    config = function(_, opts)
        local toggle_term = require("toggleterm")

        -- Windows
        if vim.fn.has("win32") == 1 then
            opts.shell_command = "pwsh.exe -NoLogo"
        end

        toggle_term.setup(opts)

        vim.keymap.set(
            "n",
            "<leader>th",
            "<CMD>:1ToggleTerm direction=horizontal<CR>",
            { desc = "ToggleTerm: Horizontal 1" }
        )
        vim.keymap.set(
            "n",
            "<leader>tt",
            "<CMD>:2ToggleTerm direction=horizontal<CR>",
            { desc = "ToggleTerm: Horizontal 2" }
        )
        vim.keymap.set(
            "n",
            "<leader>tn",
            "<CMD>:3ToggleTerm direction=horizontal<CR>",
            { desc = "ToggleTerm: Horizontal 3" }
        )
        vim.keymap.set(
            "n",
            "<leader>ts",
            "<CMD>:4ToggleTerm direction=horizontal<CR>",
            { desc = "ToggleTerm: Horizontal 4" }
        )
        vim.keymap.set("n", "<leader>tc", "<CMD>:ToggleTermToggleAll<CR>", { desc = "ToggleTerm: Toggle All" })

        function _G.set_terminal_keymaps()
            local opts = { buffer = 0 }
            vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)
            vim.keymap.set("t", "jk", [[<C-\><C-n>]], opts)
            vim.keymap.set("t", "<C-h>", [[<Cmd>wincmd h<CR>]], opts)
            vim.keymap.set("t", "<C-j>", [[<Cmd>wincmd j<CR>]], opts)
            vim.keymap.set("t", "<C-k>", [[<Cmd>wincmd k<CR>]], opts)
            vim.keymap.set("t", "<C-l>", [[<Cmd>wincmd l<CR>]], opts)
            vim.keymap.set("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()")
    end,
}

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

2 participants