-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Esc
closes the floating buffer instead of interacting with LazyGit and cancel the operation
#127
Comments
Having the same issue. Escape should not close the floating window. Only |
Sovled this issue by adding this key binding.
|
I tried something like this, but it doesn't pass escape down to lazygit map("t", "<ESC>", function()
local win = vim.api.nvim_get_current_win()
-- Do not close lazygit on escape
if not string.find(vim.api.nvim_buf_get_name(0), "lazygit") then
vim.api.nvim_win_close(win, true)
end
end, { desc = "Terminal Close term in terminal mode" }) does anyone know how to pass the escape key to lazygit in this case? |
I ended up doing this FWIW: SimonBrandner/dotfiles@a29de2c |
Thanks for posting the examples. I learned a lot reading them and then writing my own autocommand to prevent the escape key from bringing me out of the terminal mode. I was able to get it, with some help from ai, to send esc to lazygit, allowing me to use esc like i normally would outside of neovim |
I'd be open to adding such an autocmd to the floating window terminal buffer in this plugin, enabled by default but with an option to not add the autocmd. Thoughts? |
@kdheepak i think that would be helpful for newbies like me that might not know how to go about adding the workaround. thank you 👍 |
I have the same issue. I use Neovim and Lazygit. Any ideas on how to fix it? Update: vim.api.nvim_set_keymap("t", "<esc><esc>", "<c-\\><c-n>", { desc = "Enter Normal Mode" }) After removing this binding, all Lazygit bindings started working as expected. |
I have this issue too, that I need this for regular terminal use, so that I can hit vim.api.nvim_set_keymap("t", "<esc><esc>", "<c-\\><c-n>", { desc = "Enter Normal Mode" }) But when opening up lazygit, this setting is now undesirable as when I'm staging hunks I can't hit I wonder if it's plausible to delete the keymap when running lazygit and re-creating it when opening the terminal... via autocmd? |
I ended up solving it like this: function M.setup_terminal_keymaps()
-- Both <C-/> and <C-_> are mapped due to the way control characters are interpreted by terminal emulators.
-- ASCII value of '/' is 47, and of '_' is 95. When <C-/> is pressed, the terminal sends (47 - 64) which wraps around to 111 ('o').
-- When <C-_> is pressed, the terminal sends (95 - 64) which is 31. Hence, both key combinations need to be mapped.
-- <C-/> toggles the floating terminal
local ctrl_slash = "<C-/>"
local ctrl_underscore = "<C-_>"
local ctrl_alt_slash = "<C-A-/>"
local ctrl_alt_underscore = "<C-A-_>"
local floating_term_cmd = function()
vim.api.nvim_set_keymap("t", "<Esc><Esc>", "<C-\\><C-n>", { noremap = true })
require("utils.terminal").toggle_fterm()
end
local split_term_cmd = function()
vim.api.nvim_set_keymap("t", "<Esc><Esc>", "<C-\\><C-n>", { noremap = true })
require("utils.terminal").toggle_terminal_native()
end
vim.keymap.set({ "n", "i", "t", "v" }, ctrl_alt_slash, split_term_cmd, { desc = "Toggle terminal" })
vim.keymap.set({ "n", "i", "t", "v" }, ctrl_alt_underscore, split_term_cmd, { desc = "Toggle terminal" })
-- C-A-/ toggles split terminal on/off
vim.keymap.set({ "n", "i", "t", "v" }, ctrl_slash, floating_term_cmd, { desc = "Toggle native terminal" })
vim.keymap.set({ "n", "i", "t", "v" }, ctrl_underscore, floating_term_cmd, { desc = "Toggle native terminal" })
end
function M.setup_lazygit_keymaps()
map_normal_mode("<leader>gg", function()
-- if keymap <Esc><Esc> is set in terminal mode, remove it.
-- this is to enable <Esc> to navigate in LazyGit which otherwise
-- is overridden for terminal usage.
local terminal_keymaps = vim.api.nvim_get_keymap("t")
vim.notify(vim.inspect(terminal_keymaps))
for _, keymap in pairs(terminal_keymaps) do
if keymap.lhs == "<Esc><Esc>" then
vim.api.nvim_del_keymap("t", "<Esc><Esc>")
end
end
vim.cmd("LazyGit")
end)
end Now, I get the benefit of being able to hit Esc in the terminal but also use Esc while in the lazygit UI. |
@ulyssessouza -- after/ftplugin/lazygit.lua
-- This maps the esc key to its normal behavior only for lazygit terminal window.
vim.api.nvim_buf_set_keymap(0, 't', '<Esc>', '<Esc>', {noremap = true, silent = true}) This exact line is in the telescope/_extensions/lazygit.lua. file from this repo. 😁 Hope it helps! |
Description
To Reproduce
Here are the steps to reproduce the behavior using MINRC:
Ps: Couldn't run with MINRC...
Esc
,lg
to open LazyGit in a floating window/bufferTab
to browse toLocal Branches
Enter
to select a branch to see the commitsEsc
to go back (Cancel)Expected behavior
What is expected to happen:
When pressing
Esc
that should make theLocal Branches
section to go back.But what is happening is that the floating window just closes.
This avoids me to cherrypick a commit from a branch and paste it to another
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: