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

@ -26,18 +26,10 @@ function M.setup()
vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2])
end
utils.add_keymaps({
n = {
["<leader>ff"] = {
cmd = function() M.format(true) end
},
["<leader>fe"] = {
cmd = M.format_enable,
},
["<leader>fd"] = {
cmd = M.format_disable,
},
},
utils.set_keymap_list({
{ "<leader>ff", function() M.format() end },
{ "<leader>fe", function() M.format_enable() end },
{ "<leader>fd", function() M.format_disable() end },
})
end

View file

@ -1,151 +1,98 @@
local utils = require("utils")
local g = vim.g
g.mapleader = " "
g.maplocalleader = " "
local move_up = {
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"",
opts = {
expr = true
}
}
local move_up = { "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"", { expr = true } }
local move_down = { "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"", { expr = true } }
local move_down = {
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"",
opts = {
expr = true
}
}
utils.foreach({
{
"n",
{
-- Using lspsaga for hover doc
{ "K", "<Nop>", },
-- Using lspsaga finder with gr which does references
{ "grr", "<Nop>", },
{ "gra", "<Nop>", },
{ "grn", "<Nop>", },
{ "gri", "<Nop>", },
-- Navigation
{ "<C-Left>", "<C-w>h", },
{ "<C-Down>", "<C-w>j", },
{ "<C-Up>", "<C-w>k", },
{ "<C-Right>", "<C-w>l", },
{ "<C-h>", "<C-w>h", },
{ "<C-j>", "<C-w>j", },
{ "<C-k>", "<C-w>k", },
{ "<C-l>", "<C-w>l", },
-- Window
{ "<C-q>", "<C-w>q", },
local utils = require("utils")
-- Disable current highlights
{ "<Esc>", "<cmd> noh <CR>", },
utils.add_keymaps({
n = {
-- Using lspsaga for hover doc
["K"] = {
cmd = "<Nop>",
},
-- Using lspsaga finder with gr which does references
["grr"] = {
cmd = "<Nop>",
},
["gra"] = {
cmd = "<Nop>",
},
["grn"] = {
cmd = "<Nop>",
},
["gri"] = {
cmd = "<Nop>",
},
-- Navigation
["<C-Left>"] = {
cmd = "<C-w>h",
},
["<C-Down>"] = {
cmd = "<C-w>j",
},
["<C-Up>"] = {
cmd = "<C-w>k",
},
["<C-Right>"] = {
cmd = "<C-w>l",
},
["<C-h>"] = {
cmd = "<C-w>h",
},
["<C-j>"] = {
cmd = "<C-w>j",
},
["<C-k>"] = {
cmd = "<C-w>k",
},
["<C-l>"] = {
cmd = "<C-w>l",
},
-- Copies the entire file
{ "<C-c>", ":%y+<CR>", { silent = true } },
-- Window
["<C-q>"] = {
cmd = "<C-w>q",
},
-- Allow moving the cursor through wrapped lines with <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode,
-- so it doesn't alter d, y or c behaviour
{ "<Up>", move_up[1], move_up[2], },
{ "<Down>", move_down[1], move_down[2], },
{ "j", move_down[1], move_down[2], },
{ "k", move_up[1], move_up[2], },
-- Maps to remove
{ "<C-z>", "<Nop>", },
-- Disable current highlights
["<Esc>"] = {
cmd = "<cmd> noh <CR>",
},
-- Copies the entire file
["<C-c>"] = {
cmd = ":%y+<CR>",
opts = {
silent = true
}
},
-- Allow moving the cursor through wrapped lines with <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
-- Maps to remove
["<C-z>"] = {
cmd = "<Nop>",
},
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
["<leader>m"] = {
cmd = "m",
},
["[d"] = {
cmd = function()
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
{ "<leader>m", "m", },
{ "[d", function()
vim.diagnostic.jump({ count = -1, float = false })
end
},
["]d"] = {
cmd = function()
end },
{ "]d", function()
vim.diagnostic.jump({ count = 1, float = false })
end
},
end },
}
},
i = {},
v = {
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
["<tab>"] = {
cmd = ">gv",
},
["<S-tab>"] = {
cmd = "<gv",
},
{
"v",
{
{ "<Up>", move_up[1], move_up[2], },
{ "<Down>", move_down[1], move_down[2], },
{ "j", move_down[1], move_down[2], },
{ "k", move_up[1], move_up[2], },
{ "<tab>", ">gv", },
{ "<S-tab>", "<gv", },
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
["<leader>m"] = {
cmd = "m",
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
{ "<leader>m", "m", },
},
},
x = {
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
["p"] = {
cmd = "p:let @+=@0<CR>:let @\"=@0<CR>",
opts = {
silent = true
},
},
{
"x",
{
{ "<Up>", move_up[1], move_up[2], },
{ "<Down>", move_down[1], move_down[2], },
{ "j", move_down[1], move_down[2], },
{ "k", move_up[1], move_up[2], },
{ "p", "p:let @+=@0<CR>:let @\"=@0<CR>", { silent = true }, },
}
},
t = {
["<C-q>"] = {
cmd = "<C-\\><C-N>",
},
{
"t",
{
{ "<C-q>", "<C-\\><C-N>", },
}
},
})
}, function(mode_mapping)
local mode = mode_mapping[1]
local mappings = mode_mapping[2]
utils.set_keymap_list(mappings, mode)
end)

View file

@ -1,21 +1,23 @@
local utils = require("utils")
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = utils.validate_bufnr(bufnr)
local function switch_source_header()
local bufnr = utils.validate_bufnr(0)
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
local params = { uri = vim.uri_from_bufnr(bufnr) }
if clangd_client then
clangd_client.request("textDocument/switchSourceHeader", params, function(err, result)
if err then
error(tostring(err))
end
if not result then
print "Corresponding file cannot be determined"
return
end
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
end, bufnr)
clangd_client.request(
"textDocument/switchSourceHeader",
{ uri = vim.uri_from_bufnr(bufnr) },
function(err, result)
if err then
error(tostring(err))
end
if not result then
print "Corresponding file cannot be determined"
return
end
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
end, bufnr)
else
print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
end
@ -44,19 +46,9 @@ return {
"compile_flags.txt",
"configure.ac",
},
on_attach = function(_, bufnr)
local lsp_maps = {
{
"<leader>ko",
function() switch_source_header(0) end,
},
}
local keymaps = { n = {} }
for i, _ in ipairs(lsp_maps) do
local binding, cmd = unpack(lsp_maps[i])
keymaps.n[binding] = { cmd = cmd, opts = { buffer = bufnr } }
end
utils.add_keymaps(keymaps)
on_attach = function()
utils.set_keymap_list({
{ "<leader>ko", switch_source_header, },
})
end,
}

View file

@ -24,34 +24,9 @@ local function global_on_attach(client, bufnr)
})
end
utils.add_keymaps({
n = {
["gd"] = {
cmd = function()
vim.lsp.buf.definition({
reuse_win = true,
})
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr
}
},
["gD"] = {
cmd = function()
vim.lsp.buf.declaration({
reuse_win = true,
})
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

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,
}

View file

@ -1,10 +1,8 @@
local utils = require("utils")
local wm = require("window_management")
local terminal_window = nil
local terminal_bufnr = nil
local function open_terminal_window()
local utils = require("utils")
if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then
vim.cmd("botright split")
terminal_window = vim.api.nvim_get_current_win()
@ -23,6 +21,7 @@ local function toggle_terminal()
return
end
local utils = require("utils")
open_terminal_window()
local term_height = vim.api.nvim_get_option("lines")
@ -37,13 +36,7 @@ local function toggle_terminal()
vim.api.nvim_command("startinsert")
end
utils.add_keymaps({
n = {
["<leader>h"] = {
cmd = function()
toggle_terminal()
wm.autosize_windows()
end,
}
}
})
vim.keymap.set("n", "<leader>h", function()
toggle_terminal()
require("window_management").autosize_windows()
end)

View file

@ -1,10 +1,17 @@
local M = {}
local overridden_default_keymaps = {}
function M.set_keymap_list(keymap_list, mode)
mode = mode or "n"
M.foreach(keymap_list, function(mapping)
vim.keymap.set(mode, mapping[1], mapping[2], mapping[3] or {})
end)
end
local function is_single_keymap_table(map_table)
assert(map_table)
return map_table.n or map_table.t or map_table.i or map_table.v or map_table.x or map_table.o
function M.del_keymap_list(keymap_list, mode)
mode = mode or "n"
M.foreach(keymap_list, function(mapping)
vim.keymap.del(mode, mapping[1])
end)
end
function M.get_file_names_in_dir(dir, expr, strip_extension)
@ -75,94 +82,6 @@ function M.add_opts_to_all_mappings(mappings, opts)
end
end
local function pass_keymap_tbl_to_fn(maps, fn)
if is_single_keymap_table(maps) then
fn(maps)
else
for _, map_table in pairs(maps) do
fn(map_table)
end
end
end
local function get_keymaps(mode, buffer)
if buffer then
return vim.api.nvim_buf_get_keymap(buffer, mode)
end
return vim.api.nvim_get_keymap(mode)
end
function M.add_temporary_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
-- We make an assumptino here which is that all the entries are buffers, or not buffers.
-- Meaning, we only check the first entry and trust that the rest are the same.
local result = get_keymaps(mode, (function()
for _, entry in pairs(entries) do
-- nil buffer is treated as a global keymap
return entry.buffer
end
end)())
for code, _ in pairs(entries) do
for _, map in ipairs(result) do
if map.lhs == code then
if not overridden_default_keymaps[mode] then
overridden_default_keymaps[mode] = {}
end
overridden_default_keymaps[mode][code] = {
cmd = map.callback or map.rhs,
opts = {
noremap = map.noremap == 1,
expr = map.expr == 1,
silent = map.silent == 1,
nowait = map.nowait == 1,
script = map.script == 1,
buffer = type(map.buffer) == "number" and map.buffer or nil,
},
}
end
end
end
end
end)
M.add_keymaps(maps)
end
function M.add_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
for code, info in pairs(entries) do
vim.keymap.set(mode, code, info.cmd, info.opts)
end
end
end)
end
function M.remove_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
local overriden_mode = overridden_default_keymaps[mode]
for code, _ in pairs(entries) do
vim.keymap.del(mode, code)
if overriden_mode and overriden_mode[code] then
vim.keymap.set(mode, code, overriden_mode[code].cmd, overriden_mode[code].opts)
end
end
end
end)
end
function M.is_buf_filetype(bufnr, filetype)
return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype
end

View file

@ -189,75 +189,35 @@ end
function M.setup()
local resizing_mode_keymaps = {
n = {
["<Left>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "h") end
},
["<Down>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "j") end
},
["<Up>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "k") end
},
["<Right>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "l") end
},
["<Esc>"] = {
cmd = function() exit_resizing_mode() end
},
["<Enter>"] = {
cmd = function() exit_resizing_mode() end
},
["="] = {
cmd = function() M.autosize_windows() end
},
}
{ "<Left>", function() resize_window(vim.api.nvim_get_current_win(), "h") end },
{ "<Down>", function() resize_window(vim.api.nvim_get_current_win(), "j") end },
{ "<Up>", function() resize_window(vim.api.nvim_get_current_win(), "k") end },
{ "<Right>", function() resize_window(vim.api.nvim_get_current_win(), "l") end },
{ "<Esc>", function() exit_resizing_mode() end },
{ "<Enter>", function() exit_resizing_mode() end },
{ "=", function() M.autosize_windows() end },
}
local enter_resizing_mode_keymaps = {
n = {
["<C- >"] = {
cmd = function() enter_resizing_mode() end
}
},
{ "<C- >", function() enter_resizing_mode() end }
}
local window_shifting_keymaps = {
n = {
["<C-S-Left>"] = {
cmd = function()
swap_window("h")
end
},
["<C-S-Down>"] = {
cmd = function()
swap_window("j")
end
},
["<C-S-Up>"] = {
cmd = function()
swap_window("k")
end
},
["<C-S-Right>"] = {
cmd = function()
swap_window("l")
end
},
},
{ "<C-S-Left>", function() swap_window("h") end },
{ "<C-S-Down>", function() swap_window("j") end },
{ "<C-S-Up>", function() swap_window("k") end },
{ "<C-S-Right>", function() swap_window("l") end },
}
utils.add_keymaps({
window_shifting_keymaps,
enter_resizing_mode_keymaps
})
utils.set_keymap_list(window_shifting_keymaps)
utils.set_keymap_list(enter_resizing_mode_keymaps)
local function on_resize_mode_enter()
utils.remove_keymaps(enter_resizing_mode_keymaps)
utils.add_keymaps(resizing_mode_keymaps)
M.del_keymap_list(enter_resizing_mode_keymaps)
M.set_keymap_list(resizing_mode_keymaps)
end
local function on_resize_mode_exit()
utils.remove_keymaps(resizing_mode_keymaps)
utils.add_keymaps(enter_resizing_mode_keymaps)
M.del_keymap_list(resizing_mode_keymaps)
M.set_keymap_list(enter_resizing_mode_keymaps)
end
local window_management_augroup = "WindowManagementEvents"