🪴 my neovim config:)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

keybinds: use `vim.keymap.set`

robin 78498fcc ebdd80a1

+76 -136
+76 -136
config/lua/ivy/config/keybinds.lua
··· 1 - ---@diagnostic disable-next-line: missing-fields 2 - local keymaps = require("keymaps").setup() 3 - 4 - local function kmgroup(mappings) 5 - coroutine.wrap(function() 6 - vim.iter(ipairs(mappings)):each(function(_, map) 7 - if #map < 4 then 8 - vim.notify(string.format("[%s] %s", "kmgroup", "requires 4 paramaters per keymap"), vim.log.levels.WARN) 9 - return 10 - end 11 - local mode = map[1] 12 - local lhs = map[2] 13 - local rhs = map[3] 14 - local desc = map[4] 15 - 16 - vim.schedule(function() 17 - vim.keymap.set(mode, lhs, rhs, { noremap = true, silent = true, desc = desc }) 18 - end) 19 - end) 20 - end)() 21 - end 22 - 23 1 local function directionalmap(mode, lhs, f, fmt) 24 2 vim.iter(ipairs({ { "h", "left" }, { "j", "down" }, { "k", "up" }, { "l", "right" } })):each(function(_, map) 25 3 local d = map[1] ··· 37 15 end 38 16 39 17 -- [movement] 40 - kmgroup({ 41 - { { "n", "v" }, "W", "g_", "goto last non empty of line" }, 42 - { { "n", "v" }, "B", "^", "goto first non empty of line" }, 43 - }) 18 + vim.keymap.set({ "n", "v" }, "W", "g_", { desc = "goto last non empty of line" }) 19 + vim.keymap.set({ "n", "v" }, "B", "^", { desc = "goto first non empty of line" }) 44 20 45 21 -- [vertical movment] 46 - kmgroup({ 47 - { "n", "<C-d>", "<C-d>zz", "go down and center line" }, 48 - { "n", "<C-u>", "<C-u>zz", "go up and center line" }, 49 - { "n", "n", "nzzzv", "goto next search and uncover line" }, 50 - { "n", "N", "Nzzzv", "goto prev search and uncover line" }, 51 - }) 22 + vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = "go down and center line" }) 23 + vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = "go up and center line" }) 24 + vim.keymap.set("n", "n", "nzzzv", { desc = "goto next search and uncover line" }) 25 + vim.keymap.set("n", "N", "Nzzzv", { desc = "goto prev search and uncover line" }) 52 26 53 27 -- [fixup] 54 - kmgroup({ 55 - { { "n", "v" }, "<S-down>", "<nop>", "remove shift down movement" }, 56 - { { "n", "v" }, "<S-up>", "<nop>", "remove shift up movement" }, 57 - }) 28 + vim.keymap.set({ "n", "v" }, "<S-down>", "<nop>", { desc = "remove shift down movement" }) 29 + vim.keymap.set({ "n", "v" }, "<S-up>", "<nop>", { desc = "remove shift up movement" }) 58 30 59 31 -- [workspace] 60 - kmgroup({ 61 - { "n", "<leader>q", vim.cmd.quitall, "quit all" }, 62 - { "n", "<C-z>", vim.cmd.detach, "detach" }, 63 - { "n", "<leader>ft", "<Plug>(tether-select)", "select tether" }, 64 - { "n", "<leader>fT", "<cmd>Tether! select<cr>", "select tether and stop current" }, 65 - }) 32 + vim.keymap.set("n", "<leader>q", vim.cmd.quitall, { desc = "quit all" }) 33 + vim.keymap.set("n", "<C-z>", vim.cmd.detach, { desc = "detach" }) 34 + vim.keymap.set("n", "<leader>ft", "<Plug>(tether-select)", { desc = "select tether" }) 35 + vim.keymap.set("n", "<leader>fT", "<cmd>Tether! select<cr>", { desc = "select tether and stop current" }) 66 36 67 37 -- [file] 68 - kmgroup({ 69 - { "n", "<C-s>", cbcall(vim._with, { noautocmd = true }, cbcall(vim.cmd, "write")), "save file" }, 70 - { "n", "<C-j>", "<C-^>", "edit alt file" }, 71 - }) 38 + vim.keymap.set("n", "<C-s>", cbcall(vim._with, { noautocmd = true }, cbcall(vim.cmd, "write")), { desc = "save file" }) 39 + vim.keymap.set("n", "<C-j>", "<C-^>", { desc = "edit alt file" }) 72 40 73 41 -- [window movement] 74 42 directionalmap("n", "<leader>w%s", function(lhs) ··· 76 44 end, "switch window %s") 77 45 78 46 -- [fixup] 79 - vim.keymap.set("n", "s", "<nop>") 47 + vim.keymap.set("n", "s", "<nop>", { desc = "disable |s|" }) 80 48 81 49 -- [windows] 82 - kmgroup({ 83 - { "n", "sv", vim.cmd.vsplit, "split window vertical" }, 84 - { "n", "sh", vim.cmd.split, "split window horizontal" }, 85 - { "n", "q", vim.cmd.close, "close window" }, 86 - }) 50 + vim.keymap.set("n", "sv", vim.cmd.vsplit, { desc = "split window vertical" }) 51 + vim.keymap.set("n", "sh", vim.cmd.split, { desc = "split window horizontal" }) 52 + vim.keymap.set("n", "q", vim.cmd.close, { desc = "close window" }) 87 53 88 54 -- [tabs] 89 - kmgroup({ 90 - { "n", "<space><tab>]", vim.cmd.tabnext, "next tab" }, 91 - { "n", "<space><tab>[", vim.cmd.tabprev, "prev tab" }, 92 - { "n", "<space><tab>n", cbcall(vim.cmd, [[$tabedit]]), "open new tab" }, 93 - { "n", "<space><tab>d", vim.cmd.tabclose, "close current tab" }, 94 - { "n", "<space><tab>x", vim.cmd.tabclose, "close current tab" }, 95 - { 96 - "n", 97 - "<space><tab><", 98 - function() 99 - vim.cmd([[ -tabmove ]]) 100 - end, 101 - "move tab to the left", 102 - }, 103 - { 104 - "n", 105 - "<space><tab>>", 106 - function() 107 - vim.cmd([[ +tabmove ]]) 108 - end, 109 - "move tab to the right", 110 - }, 111 - }) 55 + vim.keymap.set("n", "<space><tab>]", vim.cmd.tabnext, { desc = "next tab" }) 56 + vim.keymap.set("n", "<space><tab>[", vim.cmd.tabprev, { desc = "prev tab" }) 57 + vim.keymap.set("n", "<space><tab>n", cbcall(vim.cmd, [[$tabedit]]), { desc = "open new tab" }) 58 + vim.keymap.set("n", "<space><tab>d", vim.cmd.tabclose, { desc = "close current tab" }) 59 + vim.keymap.set("n", "<space><tab>x", vim.cmd.tabclose, { desc = "close current tab" }) 60 + vim.keymap.set("n", "<space><tab><", function() 61 + vim.cmd([[ -tabmove ]]) 62 + end, { desc = "move tab to the left" }) 63 + vim.keymap.set("n", "<space><tab>>", function() 64 + vim.cmd([[ +tabmove ]]) 65 + end, { desc = "move tab to the right" }) 112 66 113 67 -- [splits] 114 - keymaps.normal["<C-\\>"] = { 115 - function() 116 - vim.cmd([[vs | wincmd l]]) 117 - end, 118 - "split file vertically", 119 - } 68 + vim.keymap.set("n", "<C-\\>", cbcall(vim.cmd, [[ vs | wincmd l ]]), { desc = "split file vertically" }) 120 69 121 70 -- [selection] 122 - kmgroup({ 123 - { "n", "<M-v>", "^vg_", "select contents of current line" }, 124 - }) 71 + vim.keymap.set("n", "<M-v>", "^vg_", { desc = "select contents of current line" }) 125 72 126 73 -- [selection] 127 74 vim.keymap.set("o", ";", "iw", { desc = "select inside word" }) ··· 151 98 end, { desc = "toggle diff mode" }) 152 99 153 100 -- [recording] 154 - kmgroup({ 155 - { "n", "Q", "q", "record macro" }, 156 - }) 101 + vim.keymap.set("n", "Q", "q", { desc = "record macro" }) 157 102 158 103 -- [treesitter] 159 104 -- vim-scriptease inspired `zS` 160 - kmgroup({ 161 - { "n", "zS", vim.show_pos, "inspect marks" }, 162 - }) 105 + vim.keymap.set("n", "zS", vim.show_pos, { desc = "inspect marks" }) 163 106 164 107 local ns = vim.api.nvim_create_namespace("resize-mode") 165 - keymaps.normal["<space>w"] = { 166 - function() 167 - vim.on_key(function(key, typed) 168 - local switch = { 169 - ["<C-H>"] = function() 170 - if vim.fn.winnr() == vim.fn.winnr("l") then 171 - return vim.fn.win_move_separator(vim.fn.winnr("h"), -1) 172 - end 173 - vim.fn.win_move_separator(vim.fn.winnr(), -1) 174 - end, 175 - ["<C-J>"] = function() 176 - if vim.fn.winnr() ~= vim.fn.winnr("j") then 177 - vim.fn.win_move_statusline(vim.fn.winnr(), 1) 178 - end 179 - vim.fn.win_move_statusline(vim.fn.winnr("k"), 1) 180 - end, 181 - ["<C-K>"] = function() 182 - if vim.fn.winnr() ~= vim.fn.winnr("j") then 183 - vim.fn.win_move_statusline(vim.fn.winnr(), -1) 184 - end 185 - vim.fn.win_move_statusline(vim.fn.winnr("k"), -1) 186 - end, 187 - ["<C-L>"] = function() 188 - if vim.fn.winnr() == vim.fn.winnr("l") then 189 - return vim.fn.win_move_separator(vim.fn.winnr("h"), 1) 190 - end 191 - vim.fn.win_move_separator(vim.fn.winnr(), 1) 192 - end, 193 - } 194 - 195 - local k = vim.fn.keytrans(typed) 196 - if k == "<Esc>" then 197 - vim.on_key(nil, ns) 198 - elseif vim.tbl_contains({ "h", "j", "k", "l" }, k) then 199 - vim.cmd.wincmd(k) 200 - elseif vim.tbl_contains(vim.tbl_keys(switch), k) then 201 - local fn = switch[k] 202 - if fn and type(fn) == "function" then 203 - fn() 108 + vim.keymap.set("n", "<space>w", function() 109 + vim.on_key(function(key, typed) 110 + local switch = { 111 + ["<C-H>"] = function() 112 + if vim.fn.winnr() == vim.fn.winnr("l") then 113 + return vim.fn.win_move_separator(vim.fn.winnr("h"), -1) 114 + end 115 + vim.fn.win_move_separator(vim.fn.winnr(), -1) 116 + end, 117 + ["<C-J>"] = function() 118 + if vim.fn.winnr() ~= vim.fn.winnr("j") then 119 + vim.fn.win_move_statusline(vim.fn.winnr(), 1) 120 + end 121 + vim.fn.win_move_statusline(vim.fn.winnr("k"), 1) 122 + end, 123 + ["<C-K>"] = function() 124 + if vim.fn.winnr() ~= vim.fn.winnr("j") then 125 + vim.fn.win_move_statusline(vim.fn.winnr(), -1) 126 + end 127 + vim.fn.win_move_statusline(vim.fn.winnr("k"), -1) 128 + end, 129 + ["<C-L>"] = function() 130 + if vim.fn.winnr() == vim.fn.winnr("l") then 131 + return vim.fn.win_move_separator(vim.fn.winnr("h"), 1) 204 132 end 133 + vim.fn.win_move_separator(vim.fn.winnr(), 1) 134 + end, 135 + } 136 + 137 + local k = vim.fn.keytrans(typed) 138 + if k == "<Esc>" then 139 + vim.on_key(nil, ns) 140 + elseif vim.tbl_contains({ "h", "j", "k", "l" }, k) then 141 + vim.cmd.wincmd(k) 142 + elseif vim.tbl_contains(vim.tbl_keys(switch), k) then 143 + local fn = switch[k] 144 + if fn and type(fn) == "function" then 145 + fn() 205 146 end 206 - return "" 207 - end, ns) 208 - end, 209 - "enter resize mode", 210 - } 147 + end 148 + return "" 149 + end, ns) 150 + end, { desc = "enter resize mode" }) 211 151 212 152 -- [terminal] 213 - keymaps.terminal["<esc><esc>"] = { [[<C-\><C-n>]], "escape terminal mode" } 153 + vim.keymap.set("t", "<esc><esc>", [[<C-\><C-n>]], { desc = "escape terminal mode" }) 214 154 215 155 -- [editing] 216 - keymaps.normal["g."] = { [[:%s/<c-r>"/<c-r>./g<cr>]], "repeat last edit for file" } 156 + vim.keymap.set("n", "g.", [[:%s/<c-r>"/<c-r>./g<cr>]], { desc = "repeat last edit for file" })