kdheepak / lazygit.nvim

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

<ESC> key not work with Lazygit inside Neovim #7

Closed tnhh00037 closed 4 years ago

tnhh00037 commented 4 years ago

I'm using 0.4.3 branch .

Currently, Lazygit has key to exit/return inside itself. But if I use it inside neovim, seems that key will switch neovim to mode, not returning for Lazygit.

Is there any solution? Thanks for your work!!

kdheepak commented 4 years ago

Thanks for using the plugin! I'm able to use ESC to in lazygit in neovim though, and it exits lazygit as expected. Do you have a tnoremap somewhere in your init.vim that maps escape to return to normal mode?

kdheepak commented 4 years ago

For what it is worth, I have something like the following in my init.vim:

function s:AddTerminalNavigation()

    echom &filetype
    if &filetype ==# ''
        tnoremap <buffer> <silent> <c-h> <c-\><c-n>:TmuxNavigateLeft<cr>
        tnoremap <buffer> <silent> <c-j> <c-\><c-n>:TmuxNavigateDown<cr>
        tnoremap <buffer> <silent> <c-k> <c-\><c-n>:TmuxNavigateUp<cr>
        tnoremap <buffer> <silent> <c-l> <c-\><c-n>:TmuxNavigateRight<cr>
    endif

endfunction

augroup TerminalNavigation
    autocmd!
    autocmd TermEnter * call s:AddTerminalNavigation()
augroup END

This adds the above keybindings to a terminal buffer when you open it, if the filetype is an empty string. Most vim plugin terminal buffers that do something specific set the name of the terminal buffer to be the name of the terminal application itself. lazygit.vim does this as well. So this won't interfere with with any similar keybindings by lazygit.

kdheepak commented 4 years ago

You can also add the following to the if block

        tnoremap <Esc> <C-\><C-n>
        tnoremap <C-v><Esc> <Esc>

I go back and forth on whether I want to use <Esc> in a normal terminal.

kdheepak commented 4 years ago

Feel free to reopen in case if you have any questions regarding this.

dantearaujo1 commented 2 years ago

@kdheepak using your suggestion makes my neovim ESC and TmuxNavigation keybinds not work when using toggleterm terminal, do you have a workaround for this? Sorry, im a noob. I understood that you have set the keybinds for terminals that don't have a filetype, but in the case of toggleterm it is the same as lazygit.

kdheepak commented 2 years ago

Hmm, why wouldn't it work? Using <C-\><C-n> in the terminal in neovim will go from insert to normal mode. Can you try it in a native neovim terminal? If it is a toggleterm issue, can you ask on the toggleterm repo?

mario-amazing commented 2 years ago

@kdheepak what is the easiest way to close LazyGit window? only Esc not working. Currently, I'm using Esc + :q

kdheepak commented 2 years ago

Just hitting q works for me. Does that work for you?

mario-amazing commented 2 years ago

Awesome, thanks! maybe you could add it to Menu, cuz this option is not obvious)

amritk commented 11 months ago

Hmm I have the opposite problem, hitting escape closes lazygit so how do you go "back"? Like when you are in the commits?

pvsfair commented 5 months ago

Hmm I have the opposite problem, hitting escape closes lazygit so how do you go "back"? Like when you are in the commits?

Have you managed to do something for this? @amritk I'm having the same problem and it is bugging me :rofl:

amritk commented 5 months ago

Yea I just deleted the keymap for escape in the terminal. The downside is I can't hit escape to close them anymore but oh well 🤷

SimonBrandner commented 4 months ago

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