log / setting up neovim-remote for better lazygit integration
Problem / Context
When using Lazygit inside a Neovim terminal, pressing e to edit a file opens a new Neovim instance inside the terminal, creating a nested editor situation. This is clunky and breaks the workflow.
What you want:
- Press
ein Lazygit → file opens in the parent Neovim instance - No nested editors
- Seamless integration between Lazygit and Neovim
The solution: Use neovim-remote (nvr) to communicate with the existing Neovim instance.
Solution / Approach
neovim-remote is a Python package that lets external programs communicate with a running Neovim instance via its RPC API. By configuring Lazygit to use nvr instead of plain nvim, files open in the existing editor.
Two-step setup:
- Install
neovim-remote - Configure Lazygit to use it
Code / Examples
Step 1: Install neovim-remote
# On macOS
brew install neovim-remote
# On Linux/Windows (via pip)
pip install neovim-remote
Step 2: Configure Lazygit
Edit your Lazygit config file (~/.config/lazygit/config.yml):
os:
editPreset: 'nvim'
edit: "nvr -l --remote {{filename}}"
Explanation of flags:
-l→ Use the “last” Neovim instance (the one you launched Lazygit from)--remote→ Open the file in the existing instance{{filename}}→ Lazygit template variable for the file path
Alternative config (open in new tab):
os:
editPreset: 'nvim'
edit: "nvr -l --remote-tab {{filename}}"
Alternative config (open in split):
os:
editPreset: 'nvim'
edit: "nvr -l -c 'vsplit {{filename}}'"
How it works:
- You open Neovim
- Inside Neovim, you open a terminal (
:terminal) - In that terminal, you run
lazygit - When you press
ein Lazygit, it usesnvrto send a “remote open” command - File opens in your Neovim instance, not a nested editor
Bonus: Set EDITOR environment variable
Add this to your shell config (~/.zshrc or ~/.bashrc):
if [ -n "$NVIM" ]; then
export EDITOR="nvr -l --remote"
else
export EDITOR="nvim"
fi
This makes $EDITOR use nvr when inside Neovim, and regular nvim otherwise.