kdheepak / lazygit.nvim

Plugin for calling lazygit from within neovim.
MIT License
1.49k stars 54 forks source link

Add callbacks to run functions when LazyGit opens/closes #74

Open fnune opened 2 years ago

fnune commented 2 years ago

I use LazyGit's default keybindings, where <space> will stage/unstage things. When writing a quick commit message inside LazyGit, one needs to use the <space> key for spaces.

Here's the problem: I have my leader key set to <space>, and apparently that still counts when the LazyGit window is open. This has one big disadvantage: any time I press <space> inside LazyGit (and I do that often), Neovim needs to wait its timeoutlen before it forwards the keypress. So every time I e.g. want to stage/unstage something, I need to wait timeoutlen or press some other key to short-cut it. When writing a commit message, every time I add a space, I need to wait timeoutlen.

I wonder if you've come across this or know of a way to solve this. One idea I had was in the title of this issue: if lazygit.nvim provided on-open and on-close callbacks, I could set <leader> to something else while LazyGit is open, and then reset it once it closes.

Thanks for your plugin <3

PS: I tried using Plenary to render the window, and LazyGit behaved the same.

kdheepak commented 2 years ago

This is a great idea! I’m on travel for a few weeks but when I’m back I’ll add this feature

fnune commented 1 year ago

Hi @kdheepak — after a while investigating this further, I realized I had a keybinding for terminal mode (which lazygit.nvim uses) mapped to <leader>something. Removing it fixes this issue for me, so I'm closing it!


--- Use <leader><esc> to exit insert mode in a terminal
-map('t', '<leader><esc>', '<C-\\><C-n>')
+-- Exit insert mode in a terminal
+map('t', '<C-t><esc>', '<C-\\><C-n>')
RomainLanz commented 1 year ago

Hey both of you! 👋🏻

I have exactly the same issue, but I am not sure what I must change to avoid having to wait for this delay.

fnune commented 1 year ago

Try :tmap to see if you have any terminal-mode mappings.

If there's a terminal mode mapping with a prefix that gets used in LazyGit, then Vim will need to decide: do I need to handle that key press or can I pass it to LazyGit's terminal already?

RomainLanz commented 1 year ago

Got it!

I had <leader>t to close my terminal, and remapped it to <ESC><ESC> did the trick. Thanks!

fnune commented 1 year ago

Note that now actions that start with ESC will be delayed in LazyGit :grin: I used C-t https://github.com/kdheepak/lazygit.nvim/issues/74#issuecomment-1307687927

Jack-Barry commented 4 months ago

@kdheepak I know this request was closed by the OP, but I'd still like something like this, unless there's a workaround available for my use case:

When the Lazygit buffer closes, I'd like to run a command to refresh my Nvim Tree buffer. Otherwise, it doesn't reflect the Git status of files accurately until I manually refresh it.

kdheepak commented 4 months ago

I can add a function that you can define during config to be run as a callback. I'll reopen this issue to track it.

yuchanns commented 1 month ago

Need this feature too. In my case, I hope to run LspRestart to update gopls while LazyGit switches the branch.