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

@ -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)