Skip to content

Instantly share code, notes, and snippets.

@jondkinney
Last active August 7, 2025 01:41
Show Gist options
  • Save jondkinney/63b8761e25f241e6f234ff1a68d41aa1 to your computer and use it in GitHub Desktop.
Save jondkinney/63b8761e25f241e6f234ff1a68d41aa1 to your computer and use it in GitHub Desktop.
LazyGit Statusline Override
--============================================================================--
--
-- Lazygit Editor Detection and Statusline Customization
--
--============================================================================--
--
-- This plugin detects when Neovim is launched from lazygit as an editor and
-- changes the statusline color to indicate this special editing mode. This helps
-- prevent confusion when editing files from within lazygit, as the editor
-- appears fullscreen and can be mistaken for a regular Neovim session.
--
-- To use this, configure lazygit to launch nvim with a flag:
-- os:
-- edit: 'nvim --cmd "let g:lazygit_editing=1" {{filename}}'
-- editAtLine: 'nvim --cmd "let g:lazygit_editing=1" +{{line}} {{filename}}'
-- editAtLineAndWait: 'nvim --cmd "let g:lazygit_editing=1" +{{line}} {{filename}}'
-- editInTerminal: true
--
-- On macOS the lazygit configuration lives here, by default: /Users/jon/Library/Application Support/lazygit/config.yml
--------------------------------------------------------------------------------
---@type LazySpec
return {
{
"nvim-lualine/lualine.nvim",
opts = function(_, opts)
-- Check if we're editing from lazygit
if vim.g.lazygit_editing == 1 then
-- Create a custom theme based on nord but with a different statusline color
local custom_nord = require "lualine.themes.nord"
-- Override the normal mode colors to use Nord red to indicate lazygit editing
custom_nord.normal.a.bg = "#BF616A" -- Nord red
custom_nord.normal.b.bg = "#D08770" -- Nord orange for contrast
custom_nord.normal.c.bg = "#434C5E" -- Keep nord2 for consistency
-- Also customize insert mode to maintain the red theme
custom_nord.insert.a.bg = "#D08770" -- Nord orange
-- Visual mode gets a purple tint
custom_nord.visual.a.bg = "#B48EAD" -- Nord purple
-- Replace mode (command mode doesn't exist in the theme)
custom_nord.replace.a.bg = "#EBCB8B" -- Nord yellow
opts.options = opts.options or {}
opts.options.theme = custom_nord
-- Add a visual indicator in the statusline
opts.sections = opts.sections or {}
opts.sections.lualine_a = opts.sections.lualine_a or { "mode" }
-- Insert the lazygit indicator after mode
table.insert(opts.sections.lualine_a, {
function() return "󰊢 LAZYGIT" end,
color = { fg = "#ECEFF4", gui = "bold" },
})
end
return opts
end,
},
{
"AstroNvim/astrocore",
opts = function(_, opts)
-- Also set up an autocmd to apply statusline highlight overrides
-- This catches any cases where lualine might not be used
opts.autocmds = opts.autocmds or {}
opts.autocmds.lazygit_editing = {
{
event = "VimEnter",
callback = function()
if vim.g.lazygit_editing == 1 then
-- Override basic statusline highlights as a fallback
vim.api.nvim_set_hl(0, "StatusLine", {
bg = "#BF616A", -- Nord red
fg = "#ECEFF4", -- Nord white
bold = true,
})
vim.api.nvim_set_hl(0, "StatusLineNC", {
bg = "#D08770", -- Nord orange
fg = "#ECEFF4",
})
-- Set a notification on startup to confirm lazygit mode
vim.defer_fn(
function()
vim.notify("Editing from Lazygit", vim.log.levels.INFO, {
title = "Lazygit Mode",
timeout = 2000,
})
end,
100
)
end
end,
},
}
return opts
end,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment