-- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here vim.keymap.set("n", "gO", function() local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1] if vim.v.shell_error ~= 0 or not git_root then vim.notify("Not in a git repository", vim.log.levels.WARN) return end local output = vim.fn.systemlist("git status --porcelain") local files = {} for _, line in ipairs(output) do if line ~= "" then local status = line:sub(1, 2) -- skip deleted files if not status:match("D") then local filepath = line:sub(4) -- handle renames: "old -> new" local arrow_pos = filepath:find(" -> ") if arrow_pos then filepath = filepath:sub(arrow_pos + 4) end if filepath ~= "" then table.insert(files, git_root .. "/" .. filepath) end end end end if #files == 0 then vim.notify("No modified files found", vim.log.levels.INFO) return end for _, file in ipairs(files) do vim.cmd.edit(vim.fn.fnameescape(file)) end vim.notify("Opened " .. #files .. " modified file(s)", vim.log.levels.INFO) end, { desc = "Open all git modified files" })