kdheepak / lazygit.nvim

Plugin for calling lazygit from within neovim.
MIT License
1.31k stars 52 forks source link

`Esc` closes the floating buffer instead of interacting with LazyGit and cancel the operation #127

Open ulyssessouza opened 3 months ago

ulyssessouza commented 3 months ago

Description

To Reproduce

Here are the steps to reproduce the behavior using MINRC: Ps: Couldn't run with MINRC...

  1. Press Esc, lg to open LazyGit in a floating window/buffer
  2. Tab to browse to Local Branches
  3. Enter to select a branch to see the commits
  4. Press Esc to go back (Cancel)

Expected behavior

What is expected to happen: When pressing Esc that should make the Local 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):

ckt114 commented 2 months ago

Having the same issue. Escape should not close the floating window. Only q should.

ckt114 commented 2 months ago

Sovled this issue by adding this key binding.

vim.keymap.del("t", "<esc>")

amritk commented 1 month ago

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?

SimonBrandner commented 2 weeks ago

I ended up doing this FWIW: https://github.com/SimonBrandner/dotfiles/commit/a29de2c408d6157760bbfe815a8b49bcb7f8f230

collinvandyck commented 1 week ago

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

kdheepak commented 1 week ago

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?

collinvandyck commented 1 week ago

@kdheepak i think that would be helpful for newbies like me that might not know how to go about adding the workaround. thank you 👍

enheit commented 1 week ago

I have the same issue. I use Neovim and Lazygit. Any ideas on how to fix it?

Update: I found the root cause of the problem. In this https://github.com/kdheepak/lazygit.nvim/issues/78#issuecomment-1416894837, I learned that a potential key binding might prevent the Esc key from working as expected. In my case, I had:

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.