toggleterm.nvim icon indicating copy to clipboard operation
toggleterm.nvim copied to clipboard

Cannot switch to normal mode in terminal when using the default key mapping <C-\>

Open cherrot opened this issue 3 years ago • 1 comments

I tried to map <ESC> to <C-\><C-n> in terminal mode to switch to the normal mode. But it doesn't work, instead, it just toggles the terminal.

Maybe it's not a good idea to use <C-\> as the default mapping?

I'm using nvim 0.7.2. Here is the plugin's config:

	-- vim.api.nvim_buf_set_keymap(0, "t", "<Esc>, [[<C-\><C-n>]], {})  -- doesn't work
	vim.api.nvim_set_keymap("t", "<Esc>, [[<C-\><C-n>]], {})

	require("toggleterm").setup({
		-- size can be a number or function which is passed the current terminal
		size = function(term)
			if term.direction == "horizontal" then
				return 15
			elseif term.direction == "vertical" then
				return vim.o.columns * 0.40
			end
		end,
		-- open_mapping = [[<c-\>]],  -- This is the default mapping.
		hide_numbers = true, -- hide the number column in toggleterm buffers
		shade_filetypes = {},
		shade_terminals = false,
		shading_factor = "1", -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
		start_in_insert = true,
		insert_mappings = true, -- whether or not the open mapping applies in insert mode
		persist_size = true,
		direction = "horizontal",
		close_on_exit = true, -- close the terminal window when the process exits
		shell = vim.o.shell, -- change the default shell
	})

cherrot avatar Aug 05 '22 11:08 cherrot

@cherrot that is not a default mapping a user can use whatever they want that is just an example. You are expected to use what works for you. I use the mapping in the docs and it's worked without issue for me for years at this point

akinsho avatar Aug 05 '22 12:08 akinsho

How do you enter normal mode within the terminal if you toggle it with <c->? How does one successfully remap switching to normal mode within the terminal using that mapping?

slacksystem avatar Apr 03 '23 01:04 slacksystem

@slacksystem I'm not sure I understand the issue the mapping I use is <C-\> not <C- that isn't a key combination. If you're wondering how to change modes please read :help :terminal for more info

akinsho avatar Apr 03 '23 07:04 akinsho

why would you ever want to switch to normal mode in a terminal window?

airtonix avatar Apr 24 '23 01:04 airtonix

why would you ever want to switch to normal mode in a terminal window?

For a variety of reasons. Yanking some output into a register, scrolling up through the history, etc

slacksystem avatar Apr 24 '23 19:04 slacksystem