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 e in 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:

  1. Install neovim-remote
  2. 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:

  1. You open Neovim
  2. Inside Neovim, you open a terminal (:terminal)
  3. In that terminal, you run lazygit
  4. When you press e in Lazygit, it uses nvr to send a “remote open” command
  5. 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.

References

Written on 2025-11-09 15:50:00 +0700 Edited on 2025-11-09 15:50:00 +0700