DEV Community

Felix
Felix

Posted on

1 1

neovim and lazygit, perfect harmony

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

  1. When I open lazygit with the LazyGit command, it does not open at the current file in my buffer I opened from

  2. When 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" })
Enter fullscreen mode Exit fullscreen mode

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}}"
Enter fullscreen mode Exit fullscreen mode

Pretty cool stuff!

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
ddebajyati profile image
Debajyati Dey

Wow!

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more