Large keymapping overhaul

This commit is contained in:
Martin Larsson 2025-05-30 13:57:11 +02:00
parent 11af8c9452
commit 9fb6438efa
9 changed files with 27 additions and 81 deletions

View file

@ -48,7 +48,7 @@ return {
}, },
on_attach = function() on_attach = function()
utils.set_keymap_list({ utils.set_keymap_list({
{ "<leader>ko", switch_source_header, }, { "<leader>h", switch_source_header, },
}) })
end, end,
} }

View file

@ -1,4 +1,3 @@
local utils = require("utils")
local M = {} local M = {}
M.format_on_save = true M.format_on_save = true
@ -21,16 +20,11 @@ function M.setup()
local user_commands = { local user_commands = {
{ "FormatEnable", "lua require('format_handler').format_enable()" }, { "FormatEnable", "lua require('format_handler').format_enable()" },
{ "FormatDisable", "lua require('format_handler').format_disable()" }, { "FormatDisable", "lua require('format_handler').format_disable()" },
{ "Format", "lua require('format_handler').format(true)" },
} }
for _, cmd in ipairs(user_commands) do for _, cmd in ipairs(user_commands) do
vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2]) vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2])
end end
utils.set_keymap_list({
{ "<leader>ff", function() M.format(true) end },
{ "<leader>fe", function() M.format_enable() end },
{ "<leader>fd", function() M.format_disable() end },
})
end end
return M return M

View file

@ -11,13 +11,12 @@ utils.foreach({
{ {
"n", "n",
{ {
-- Using lspsaga for hover doc
{ "K", "<Nop>", }, { "K", "<Nop>", },
-- Using lspsaga finder with gr which does references
{ "grr", "<Nop>", },
{ "gra", "<Nop>", },
{ "grn", "<Nop>", }, { "grn", "<Nop>", },
{ "gra", "<Nop>", },
{ "grr", "<Nop>", },
{ "gri", "<Nop>", }, { "gri", "<Nop>", },
{ "gO", "<Nop>", },
-- Navigation -- Navigation
{ "<C-Left>", "<C-w>h", }, { "<C-Left>", "<C-w>h", },
{ "<C-Down>", "<C-w>j", }, { "<C-Down>", "<C-w>j", },

View file

@ -1,6 +1,5 @@
local utils = require("utils") local utils = require("utils")
local inlay_hints_handler = require("inlay_hints_handler") local lsplib = require("lsplib")
local format_handler = require("format_handler")
vim.lsp.config("*", { vim.lsp.config("*", {
root_markers = { ".git" }, root_markers = { ".git" },
@ -18,28 +17,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
local bufnr = args.buf local bufnr = args.buf
assert(client, "LspAttach: client is nil") assert(client, "LspAttach: client is nil")
inlay_hints_handler.add_buffer(bufnr) lsplib.configure_generic_client(client, bufnr)
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
format_handler.format()
end,
})
end
-- Built-in LSP completion.
-- Could switch to this if they just appeared automatically when typing, and didn't
-- only rely on showing when the servers completionCharacters are typed.
-- if client:supports_method("textDocument/completion") then
-- vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true })
-- end
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 end
}) })

View file

@ -44,18 +44,6 @@ return {
roles = { roles = {
user = "Martin", user = "Martin",
}, },
keymaps = {
send = {
modes = {
i = { "<C-CR>", "<C-s>" },
},
},
completion = {
modes = {
i = "<C-x>",
},
},
},
slash_commands = { slash_commands = {
["buffer"] = { ["buffer"] = {
opts = { opts = {

View file

@ -16,6 +16,6 @@ return {
lazy = true, lazy = true,
opts = {}, opts = {},
keys = { keys = {
{ "<leader>g", function() require("neogit").open() end } { "<leader>v", function() require("neogit").open() end }
}, },
} }

View file

@ -1,7 +1,3 @@
local utils = require("utils")
local inlay_hints_handler = require("inlay_hints_handler")
local format_handler = require("format_handler")
return { return {
"mrcjkb/rustaceanvim", "mrcjkb/rustaceanvim",
version = "^5", version = "^5",
@ -17,24 +13,7 @@ return {
}, },
}, },
server = { server = {
on_attach = function(client, bufnr) on_attach = require("lsplib").configure_generic_client,
inlay_hints_handler.add_buffer(bufnr)
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
format_handler.format()
end,
})
end
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,
} }
} }
end, end,

View file

@ -60,17 +60,26 @@ return {
}, },
}, },
keys = { keys = {
{ "gB", function() Snacks.gitbrowse() end, }, { "gB", function() Snacks.gitbrowse() end, },
{ "<leader>z", function() Snacks.zen() end, }, { "<leader>z", function() Snacks.zen() end, },
{ "<leader>f", function() Snacks.picker.smart({ multi = { "buffers", "files" } }) end, },
{ "<leader>g", function() Snacks.picker.grep() end, },
{ "<leader>l", function() Snacks.picker.git_log_file() end, },
{ "<leader>s", function() Snacks.picker.lsp_workspace_symbols() end, },
{ "<leader>n", function() Snacks.picker.notifications() end },
{ "<leader>rf", function() Snacks.rename.rename_file({}) end }, { "<leader>f", function() Snacks.picker.smart({ multi = { "buffers", "files" } }) end, },
{ "<leader>g", function() Snacks.picker.grep() end, },
{ "<leader>l", function() Snacks.picker.git_log_file() end, },
{ "<leader>s", function() Snacks.picker.lsp_workspace_symbols() end, },
{ "<leader>o", function() Snacks.picker.lsp_symbols() end, },
{ "<leader>n", function() Snacks.picker.notifications() end },
{ "<leader>d", function() Snacks.picker.diagnostics() end },
{ "<leader>e", function() Snacks.rename.rename_file({}) end },
{ "gd", function() Snacks.picker.lsp_definitions() end, },
{ "gD", function() Snacks.picker.lsp_declarations() end, },
{ "gr", function() Snacks.picker.lsp_references() end, nowait = true, },
{ "gi", function() Snacks.picker.lsp_implementations() end, },
{ "gt", function() Snacks.picker.lsp_type_definitions() end, },
}, },
init = function() init = function()
vim.api.nvim_create_autocmd("User", { vim.api.nvim_create_autocmd("User", {

View file

@ -36,7 +36,7 @@ local function toggle_terminal()
vim.api.nvim_command("startinsert") vim.api.nvim_command("startinsert")
end end
vim.keymap.set("n", "<leader>h", function() vim.keymap.set("n", "<leader>t", function()
toggle_terminal() toggle_terminal()
require("window_management").autosize_windows() require("window_management").autosize_windows()
end) end)