I enjoy using both lazygit and nvim, I even have the lazygit.nvim plugin, but a couple things are stopping my setup from being better
When I open lazygit with the
LazyGitcommand, it does not open at the current file in my buffer I opened fromWhen I want to edit a file highlighted in lazygit, I cannot do it in the window I opened lazy git from, only in the current floating pane
This can be improved!
First, I added a new keymap to my nvim config to launch lazygit and then do a search for the filename from the current buffer
vim.keymap.set("n", "<leader>lg", function()
-- get file name with extension
local file = vim.fn.expand("%:t")
vim.cmd("LazyGit")
-- Wait a bit for LazyGit to load
vim.defer_fn(function()
-- search for the file, highlight, and exit search mode in lazygit
vim.api.nvim_feedkeys("/" .. file, "t", true)
vim.api.nvim_input("<CR>")
vim.api.nvim_input("<ESC>")
end, 150) -- (milliseconds)
end, { desc = "[g]it" })
And then in my lazygit config, I used nvr (neovim remote) to launch when hitting e to edit the file
os:
editPreset: 'nvim'
# Using -l here to change to the previous window via ":wincmd p".
edit: "nvr -l --remote {{filename}}"
Pretty cool stuff!
Edit as of 27 January 2026
This stopped working as elegantly for me, the edit command was working, but would not close LazyGit and I had to close it manually (gross).
I have fixed it, if you are having issues try this workaround:
lazygit config.yml
os:
editPreset: 'nvim'
edit: "if [ -n \"$NVIM\" ]; then nvim --server $NVIM --remote-send '<C-\\><C-n><cmd>close<cr>' && nvim --server $NVIM --remote {{filename}}; else nvim {{filename}}; fi"
editInTerminal: true
Looks a little hacky but it works!
Top comments (2)
Wow!
Legend! Thank you