kdheepak / lazygit.nvim

Plugin for calling lazygit from within neovim.
MIT License
1.51k stars 56 forks source link

Bug exiting lazyGit #78

Open paulhmurray opened 2 years ago

paulhmurray commented 2 years ago

Describe the bug Loading LazyGit with NeoVim plugin there is conflict when using Esc and then trying to exit LazyGit with 'q' command for quit

To Reproduce Steps to reproduce the behavior:

Load LazyGit Press Esc Then try and leave LazyGit by pressing 'q' for quit won't work Only way to exit is to use Vim's ":q" Expected behavior That exiting the floating LazyGit screen will work regardless of pressing the 'esc' button

Screenshots Not much need for a screenshot, as the floating LazyGit window just hangs until I select ":q" for vim exit

Version info: LazyGit Version 0.34 Git version 2.34.1

huyz commented 2 years ago

I'm not sure if my issue is related or not, but I can't exit out of LazyGit anymore. Whether I hit q, <Esc>, or Ctrl+C, it just gives a blank screen and I have to :q to exit. I do see an error at the bottom that says:

^I...uyz/git/+huyz/dot-vim/plugged/lazygit.nvim/lua/lazygit.lua:28: in function <...uyz/git/+huyz/dot-vim/plugged/lazygit.nvim/lua/lazygit.lua:17>

It seems there's some sort of exception at https://github.com/kdheepak/lazygit.nvim/blob/c7a8bfb6062e57f3f7cc735720893f2706e6fc8e/lua/lazygit.lua#L29

@paulhmurray do you see the same error?

thefux commented 2 years ago

can't reproduce on my side, maybe clashes with some configuration or mapping from other plugin !?

huyz commented 2 years ago

I was able to resolve the error. I use a TermClose autocmd, as suggested in the neovim docs, but that sample code interferes with lazygit's exit.

This works though:

    " NOTE: added lazygit check to avoid lua error
    " NOTE: added "silent!" to avoid error when FZF terminal window is closed.
    autocmd TermClose * if &filetype != 'lazygit' && !v:event.status | silent! exe 'bdelete! '..expand('<abuf>') | endif
gcleroux commented 1 year ago

I was able to reproduce the bug with ToggleTerm installed. Like @thefux said, it might be a conflict somewhere in the configs.

drewxs commented 1 year ago

See if you have the following keymap set somewhere (i.e. your toggleterm setup file). Either remove it or rebind it to something else.

vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)

from: https://github.com/akinsho/toggleterm.nvim#terminal-window-mappings

eddyekofo94 commented 10 months ago

The bug is still not fixed?

kdheepak commented 10 months ago

Are you able to reproduce this bug with a minimal neovim setup? For example with a file like this:

https://github.com/kdheepak/lazygit.nvim/blob/de35012036d43bca03628d40d083f7c02a4cda3f/tests/MINRC#L1-L22

I don't believe this is a bug in lazygit.nvim per say, just a configuration collision. In neovim's terminal mode, hitting esc may or may not change the terminal mode to normal mode, depending on your configuration. See comments above for the conflicting configuration.

carmen-gh commented 7 months ago

I don't have any other Terminal Plugin like toggleTerm. But with following keymapping the plugin is not usable. After disabling this mapping it works vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" })

also mapping like this is causing problems. So rebinding it does not help.

vim.keymap.set("t", "jj", "<C-\\><C-n>", { desc = "Exit terminal mode" })

Is there a way to enable these mappings for non lazygit terminals or disable them for lazygit terminal windows?

kdheepak commented 7 months ago

When lazygit.nvim opens a terminal it sets the buffer name to lazygit. You can use an autocmd to check for the buffer name on BufOpen and set whatever bindings you want conditionally.