Large rewrite, simplify keymapping, utilize as much keys from Lazy as

possible. Reduce manually setup plugins and utilize opts instead.
This commit is contained in:
Martin Larsson 2025-02-23 01:35:23 +00:00
parent 72eb62b9cb
commit 43020a4d12
17 changed files with 408 additions and 780 deletions

View file

@ -3,53 +3,37 @@ return {
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
{ 'echasnovski/mini.diff', version = false },
{ "stevearc/dressing.nvim", opts = {} },
},
config = function()
require("codecompanion").setup({
strategies = {
chat = {
adapter = "copilot",
},
inline = {
adapter = "copilot",
},
agent = {
adapter = "copilot",
},
opts = {
strategies = {
chat = {
adapter = "copilot",
},
adapters = {
copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end,
inline = {
adapter = "copilot",
},
display = {
diff = {
provider = "mini_diff",
},
agent = {
adapter = "copilot",
},
opts = {
log_level = "DEBUG",
},
adapters = {
copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end,
},
display = {
diff = {
provider = "mini_diff",
},
})
local keymaps = {
n = {
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
["<Leader>cc"] = { cmd = "<cmd>CodeCompanionChat toggle<cr>" },
["<Leader>cm"] = { cmd = "<cmd>CodeCompanion /commit<cr>" },
},
v = {
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
["ga"] = { cmd = "<cmd>CodeCompanionAdd<cr>" },
["<Leader>ce"] = { cmd = "<cmd>CodeCompanion /explain<cr>" },
["<Leader>cf"] = { cmd = "<cmd>CodeCompanion /fix<cr>" },
["<Leader>ct"] = { cmd = "<cmd>CodeCompanion /tests<cr>" },
}
}
local utils = require("utils")
utils.add_opts_to_all_mappings(keymaps, { silent = true })
utils.add_keymaps(keymaps)
},
opts = {
log_level = "DEBUG",
},
},
keys = {
{ "<Leader>ci", "<cmd>CodeCompanion<cr>" },
{ "<Leader>cc", "<cmd>CodeCompanionChat toggle<cr>" },
{ "<Leader>ce", "<cmd>CodeCompanion /explain<cr>", mode = "v" },
},
init = function()
vim.cmd([[cab cc CodeCompanion]])
end
}

View file

@ -3,24 +3,16 @@ return {
build = "make",
event = "VeryLazy",
lazy = true,
config = function()
require("codesnap").setup({
mac_window_bar = true,
title = "codesnap.nvim",
code_font_family = "JetBrainsMono Nerd Font",
breadcrumbs_separator = "/",
has_breadcrumbs = true,
bg_theme = "grape",
watermark = "",
})
require("utils").add_keymaps({
v = {
["<leader>cs"] = {
cmd = ":CodeSnap<CR>",
opts = { silent = true },
},
}
})
end,
opts = {
mac_window_bar = true,
title = "codesnap.nvim",
code_font_family = "JetBrainsMono Nerd Font",
breadcrumbs_separator = "/",
has_breadcrumbs = true,
bg_theme = "grape",
watermark = "",
},
keys = {
{ "<leader>cs", ":CodeSnap<CR>", mode = "v", silent = true, noremap = true },
},
}

View file

@ -1,18 +1,18 @@
return {
"github/copilot.vim",
config = function()
event = "InsertEnter",
init = function()
vim.g.copilot_no_tab_map = true
require("utils").add_keymaps({
i = {
["<Right>"] = {
cmd = 'copilot#Accept("\\<Right>")',
opts = {
expr = true,
replace_keycodes = false,
silent = true,
}
}
}
})
end
end,
keys = {
{
"<Right>",
'copilot#Accept("\\<Right>")',
mode = "i",
expr = true,
replace_keycodes = false,
silent = true,
desc = "Copilot Accept with <Right>",
},
},
}

View file

@ -1,95 +1,86 @@
return {
"b0o/incline.nvim",
dependencies = {
"lewis6991/gitsigns.nvim"
{
"lewis6991/gitsigns.nvim",
opts = {},
keys = {
{ "[g", function() require("gitsigns").nav_hunk("prev") end, },
{ "]g", function() require("gitsigns").nav_hunk("next") end, },
}
}
},
event = "VeryLazy",
lazy = true,
config = function()
local gitsigns = require("gitsigns")
gitsigns.setup({})
local devicons = require("nvim-web-devicons")
require("incline").setup({
window = {
padding = 0,
},
hide = {
cursorline = true,
},
render = function(props)
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
if filename == "" then
filename = "[No Name]"
end
local ft_icon, ft_color = devicons.get_icon_color(filename)
opts = {
window = {
padding = 0,
},
hide = {
cursorline = true,
},
render = function(props)
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
if filename == "" then
filename = "[No Name]"
end
local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename)
local function get_git_diff()
local icons = { removed = "", changed = "", added = "" }
local signs = vim.b[props.buf].gitsigns_status_dict
local labels = {}
if signs == nil then
return labels
end
for name, icon in pairs(icons) do
if tonumber(signs[name]) and signs[name] > 0 then
table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name })
end
end
if #labels > 0 then
table.insert(labels, { "" })
end
local function get_git_diff()
local icons = { removed = "", changed = "", added = "" }
local signs = vim.b[props.buf].gitsigns_status_dict
local labels = {}
if signs == nil then
return labels
end
local function get_diagnostic_label()
local icons = { error = "", warn = "", info = "", hint = "" }
local label = {}
for severity, icon in pairs(icons) do
local n = #vim.diagnostic.get(props.buf,
{ severity = vim.diagnostic.severity[string.upper(severity)] })
if n > 0 then
table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity })
end
for name, icon in pairs(icons) do
if tonumber(signs[name]) and signs[name] > 0 then
table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name })
end
if #label > 0 then
table.insert(label, { "" })
end
if #labels > 0 then
table.insert(labels, { "" })
end
return labels
end
local function get_diagnostic_label()
local icons = { error = "", warn = "", info = "", hint = "" }
local label = {}
for severity, icon in pairs(icons) do
local n = #vim.diagnostic.get(props.buf,
{ severity = vim.diagnostic.severity[string.upper(severity)] })
if n > 0 then
table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity })
end
return label
end
if #label > 0 then
table.insert(label, { "" })
end
return label
end
local function get_arrow_label()
local statusline = require("arrow.statusline")
if statusline.is_on_arrow_file(props.buf) == nil then
return ""
end
local function get_arrow_label()
local statusline = require("arrow.statusline")
if statusline.is_on_arrow_file(props.buf) == nil then
return ""
end
return " " .. statusline.text_for_statusline_with_icons(props.buf)
end
return " " .. statusline.text_for_statusline_with_icons(props.buf)
end
return {
guibg = "#1e2030",
guifg = "#cad3f5",
{ " " },
{ get_diagnostic_label() },
{ get_git_diff() },
{ (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" },
{ filename .. "", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" },
{ get_arrow_label() .. "" .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" },
{ " " }
}
end,
require("utils").add_keymaps({
n = {
["[g"] = {
cmd = function() gitsigns.nav_hunk("prev") end
},
["]g"] = {
cmd = function() gitsigns.nav_hunk("next") end
}
}
})
})
end,
return {
guibg = "#1e2030",
guifg = "#cad3f5",
{ " " },
{ get_diagnostic_label() },
{ get_git_diff() },
{ (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" },
{ filename .. "", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" },
{ get_arrow_label() .. "" .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" },
{ " " }
}
end,
},
}

View file

@ -1,3 +1,15 @@
local function leap_across_windows()
require("leap").leap({
target_windows = require("leap.user").get_focusable_windows()
})
end
local function leap_in_current_buffer()
require("leap").leap({
target_windows = { vim.api.nvim_get_current_win() }
})
end
local saved_hlsearch = false
local saved_highlights = {}
local colors = require("ayu.colors")
@ -19,7 +31,13 @@ return {
},
event = "VeryLazy",
lazy = true,
config = function()
opts = {},
keys = {
{ "m", function() leap_across_windows() end, mode = "n" },
{ "m", function() leap_in_current_buffer() end, mode = "v" },
{ "m", function() leap_in_current_buffer() end, mode = "o" },
},
init = function()
local leap = require("leap")
-- Disable auto jumping to the first match
@ -53,42 +71,5 @@ return {
for _, cmd in ipairs(autocmds) do
utils.create_user_event_cb(cmd.event_name, cmd.cb, leap_augroup_name)
end
local leap_user = require("leap.user")
local function leap_across_windows()
leap.leap({
target_windows = leap_user.get_focusable_windows()
})
end
local function leap_in_current_buffer()
leap.leap({
target_windows = { vim.api.nvim_get_current_win() }
})
end
utils.add_keymaps({
n = {
["m"] = {
cmd = function()
leap_across_windows()
end,
},
},
v = {
["m"] = {
cmd = function()
leap_in_current_buffer()
end,
}
},
o = {
["m"] = {
cmd = function()
leap_in_current_buffer()
end,
}
}
})
end,
}

View file

@ -7,59 +7,36 @@ return {
dependencies = {
"nvim-tree/nvim-web-devicons",
},
after = "nvim-lspconfig",
config = function()
require("lspsaga").setup({
request_timeout = 750,
symbol_in_winbar = {
enable = false,
},
implement = {
enable = false,
},
outline = {
enable = false,
win_width = 52,
},
ui = {
border = "rounded",
title = false,
},
code_action = {
extend_gitsigns = true
},
hover = {
jump_on_first_press = true
},
})
local keymaps = {
n = {
["K"] = {
cmd = ":Lspsaga hover_doc<CR>"
},
["<leader>rn"] = {
cmd = ":Lspsaga rename<CR>"
},
["gr"] = {
cmd = ":Lspsaga finder<CR>"
},
["<leader>lt"] = {
cmd = ":Lspsaga peek_type_definition<CR>"
},
["<leader>ld"] = {
cmd = ":Lspsaga peek_definition<CR>"
},
["<leader>ca"] = {
cmd = ":Lspsaga code_action<CR>"
},
["<leader>lc"] = {
cmd = ":Lspsaga incoming_calls<CR>"
},
}
}
local utils = require("utils")
utils.add_opts_to_all_mappings(keymaps, { silent = true })
utils.add_keymaps(keymaps)
end,
opts = {
request_timeout = 750,
symbol_in_winbar = {
enable = false,
},
implement = {
enable = false,
},
outline = {
enable = false,
win_width = 52,
},
ui = {
border = "rounded",
title = false,
},
code_action = {
extend_gitsigns = true
},
hover = {
jump_on_first_press = true
},
},
keys = {
{ "K", ":Lspsaga hover_doc<CR>", silent = true, },
{ "<leader>rn", ":Lspsaga rename<CR>", silent = true, },
{ "gr", ":Lspsaga finder<CR>", silent = true, },
{ "<leader>lt", ":Lspsaga peek_type_definition<CR>", silent = true, },
{ "<leader>ld", ":Lspsaga peek_definition<CR>", silent = true, },
{ "<leader>ca", ":Lspsaga code_action<CR>", silent = true, },
{ "<leader>lc", ":Lspsaga incoming_calls<CR>", silent = true, },
},
}

View file

@ -1,7 +1,5 @@
local wm = require("window_management")
local function resize_mode()
if wm.is_in_resizing_mode() then
if require("window_management").is_in_resizing_mode() then
return "▲ Resizing ▼"
else
return ""
@ -15,46 +13,44 @@ return {
},
event = "VeryLazy",
lazy = true,
config = function()
require("lualine").setup {
options = {
theme = "ayu",
section_separators = {
left = "",
right = "",
},
component_separators = {
left = "",
right = ""
},
icons_enabled = true,
opts = {
options = {
theme = "ayu",
section_separators = {
left = "",
right = "",
},
sections = {
lualine_a = { "mode" },
lualine_b = {
"branch",
{
"diagnostics",
sources = { "nvim_lsp" },
sections = { "error", "warn", "info", "hint" },
update_in_insert = false,
},
resize_mode,
component_separators = {
left = "",
right = ""
},
icons_enabled = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = {
"branch",
{
"diagnostics",
sources = { "nvim_lsp" },
sections = { "error", "warn", "info", "hint" },
update_in_insert = false,
},
lualine_c = { "buffers" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" }
resize_mode,
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {}
},
tabline = {},
}
end
lualine_c = { "buffers" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" }
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {}
},
tabline = {},
}
}

View file

@ -14,16 +14,8 @@ return {
},
event = "VeryLazy",
lazy = true,
config = function()
local neogit = require("neogit")
neogit.setup()
require("utils").add_keymaps({
n = {
["<leader>g"] = {
cmd = function() neogit.open({ kind = "vsplit" }) end,
},
}
})
end
opts = {},
keys = {
{ "<leader>g", function() require("neogit").open({ kind = "vsplit" }) end }
},
}

View file

@ -5,81 +5,57 @@ local are_stepping_keymaps_active = false
return {
"mfussenegger/nvim-dap",
dependencies = {
"rcarriga/nvim-dap-ui",
{
"rcarriga/nvim-dap-ui",
opts = {
controls = {
enabled = false,
},
layouts = {
{
elements = {
{
id = "watches",
size = 0.5
},
{
id = "stacks",
size = 0.5
}
},
position = "bottom",
size = 15
}
},
},
},
-- Special adapters
"leoluz/nvim-dap-go",
"mfussenegger/nvim-dap-python",
{ "leoluz/nvim-dap-go", opts = {} },
{ "mfussenegger/nvim-dap-python", },
{ "nvim-neotest/nvim-nio", lazy = true },
"LiadOz/nvim-dap-repl-highlights",
"theHamsta/nvim-dap-virtual-text",
"Weissle/persistent-breakpoints.nvim",
{ "nvim-neotest/nvim-nio", lazy = true },
{ "LiadOz/nvim-dap-repl-highlights", opts = {} },
{ "theHamsta/nvim-dap-virtual-text", opts = {} },
{ "Weissle/persistent-breakpoints.nvim", opts = { load_breakpoints_event = { "BufReadPost" } } },
},
config = function()
local dap = require("dap")
local dapui = require("dapui")
-- Special adapters
require("dap-go").setup()
require("dap-python").setup("python3")
-- Special adapters
require("dap.ext.vscode").load_launchjs()
require("persistent-breakpoints").setup {
load_breakpoints_event = { "BufReadPost" }
}
require("nvim-dap-repl-highlights").setup()
require("nvim-dap-virtual-text").setup()
local virtual_text = require("nvim-dap-virtual-text/virtual_text")
local breakpoint_api = require("persistent-breakpoints.api")
dapui.setup({
controls = {
enabled = false,
},
layouts = {
{
elements = {
{
id = "watches",
size = 0.5
},
{
id = "stacks",
size = 0.5
}
},
position = "bottom",
size = 15
}
},
})
local stepping_keymaps = {
n = {
["m"] = {
cmd = function()
dap.step_out()
end
},
["n"] = {
cmd = function()
dap.step_over()
end
},
["i"] = {
cmd = function()
dap.step_into()
end
},
}
{ "m", function() dap.step_out() end },
{ "n", function() dap.step_over() end },
{ "i", function() dap.step_into() end },
}
local function enter_debug_mode()
dapui.open()
require("dapui").open()
if not are_stepping_keymaps_active then
utils.add_temporary_keymaps(stepping_keymaps)
utils.set_keymap_list(stepping_keymaps)
are_stepping_keymaps_active = true
end
@ -87,9 +63,9 @@ return {
end
local function exit_debug_mode()
dapui.close()
require("dapui").close()
if are_stepping_keymaps_active then
utils.remove_keymaps(stepping_keymaps)
utils.del_keymap_list(stepping_keymaps)
are_stepping_keymaps_active = false
end
@ -117,36 +93,17 @@ return {
exit_debug_mode()
end
utils.add_keymaps({
n = {
["<leader>dr"] = {
cmd = function()
dap.continue()
end
},
["<leader>bt"] = {
cmd = function()
breakpoint_api.toggle_breakpoint()
end
},
["<leader>bc"] = {
cmd = function()
breakpoint_api.set_conditional_breakpoint()
end
},
["<leader>br"] = { -- breakpoint remove
cmd = function()
breakpoint_api.clear_all_breakpoints()
end
},
["<leader>ds"] = {
cmd = function()
dap.disconnect({ terminateDebuggee = true })
dap.close()
exit_debug_mode()
end
},
}
local function dap_stop()
dap.disconnect({ terminateDebuggee = true })
dap.close()
exit_debug_mode()
end
utils.set_keymap_list({
{ "<leader>dr", dap.continue },
{ "<leader>bt", breakpoint_api.toggle_breakpoint },
{ "<leader>bc", breakpoint_api.set_conditional_breakpoint },
{ "<leader>br", breakpoint_api.clear_all_breakpoints },
{ "<leader>ds", dap_stop },
})
end,
}

View file

@ -30,29 +30,9 @@ return {
})
end
utils.add_keymaps({
n = {
["gd"] = {
cmd = function()
vim.lsp.buf.definition()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr,
}
},
["gD"] = {
cmd = function()
vim.lsp.buf.declaration()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr,
}
},
}
utils.set_keymap_list({
{ "gd", function() vim.lsp.buf.definition({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
{ "gD", function() vim.lsp.buf.declaration({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
})
end,
}