diff --git a/config/lua/ivy/config/keymaps.lua b/config/lua/ivy/config/keymaps.lua index c6ca780..fe237af 100644 --- a/config/lua/ivy/config/keymaps.lua +++ b/config/lua/ivy/config/keymaps.lua @@ -1,65 +1,83 @@ -local function cbcall(fn, ...) - local props = { ... } +local function wrap(fn, ...) + local props = vim.F.pack_len(...) return function() - pcall(fn, unpack(props)) + pcall(fn, vim.F.unpack_len(props)) end end --- [movement] -vim.keymap.set({ "n", "x" }, "j", [[v:count == 0 ? 'gj' : 'j']], { desc = "move down by visible lines", expr = true }) -vim.keymap.set({ "n", "x" }, "k", [[v:count == 0 ? 'gk' : 'k']], { desc = "move up by visible lines", expr = true }) -vim.keymap.set({ "n", "v" }, "W", "g_", { desc = "goto last non empty of line" }) -vim.keymap.set({ "n", "v" }, "B", "^", { desc = "goto first non empty of line" }) - --- [vertical movment] -vim.keymap.set("n", "n", "nzzzv", { desc = "goto next search and uncover line" }) -vim.keymap.set("n", "N", "Nzzzv", { desc = "goto prev search and uncover line" }) - --- [fixup] -vim.keymap.set({ "n", "v" }, "", "", { desc = "remove shift down movement" }) -vim.keymap.set({ "n", "v" }, "", "", { desc = "remove shift up movement" }) - --- [workspace] -vim.keymap.set("n", "q", vim.cmd.quitall, { desc = "quit all" }) -vim.keymap.set("n", "", vim.cmd.detach, { desc = "detach" }) -vim.keymap.set("n", "ft", "(tether-select)", { desc = "select tether" }) -vim.keymap.set("n", "fT", "Tether! select", { desc = "select tether and stop current" }) - --- [file] -vim.keymap.set("n", "", cbcall(vim._with, { noautocmd = true }, cbcall(vim.cmd, "write")), { desc = "save file" }) -vim.keymap.set("n", "", "", { desc = "edit alt file" }) - --- [windows] -vim.keymap.set("n", "s", "", { desc = "win prefix" }) +-- move down by visible lines +vim.keymap.set( + { "n", "x" }, + "j", + [[v:count == 0 ? 'gj' : 'j']], + { expr = true } +) +-- move up by visible lines +vim.keymap.set( + { "n", "x" }, + "k", + [[v:count == 0 ? 'gk' : 'k']], + { expr = true } +) +-- goto last non empty of line +vim.keymap.set({ "n", "v" }, "W", "g_") +-- goto first non empty of line +vim.keymap.set({ "n", "v" }, "B", "^") + +-- goto next search and uncover line +vim.keymap.set("n", "n", "nzzzv") +-- goto prev search and uncover line +vim.keymap.set("n", "N", "Nzzzv") + +-- remove shift down movement +vim.keymap.set({ "n", "v" }, "", "") +-- remove shift up movement +vim.keymap.set({ "n", "v" }, "", "") + +-- quit all +vim.keymap.set("n", "q", vim.cmd.quitall) +-- detach +vim.keymap.set("n", "", vim.cmd.detach) + +-- save file without autocmds +vim.keymap.set( + "n", + "", + wrap(vim._with, { noautocmd = true }, wrap(vim.cmd, "write")) +) +-- edit alt file +vim.keymap.set("n", "", "") --- [splits] -vim.keymap.set("n", "", cbcall(vim.cmd, [[ vs | wincmd l ]]), { desc = "split file vertically" }) +-- win prefix +vim.keymap.set("n", "s", "") --- [selection] -vim.keymap.set("n", "", "^vg_", { desc = "visually select contents of current line" }) +vim.keymap.set("n", "gV", '"g`[" . strpart(getregtype(), 0, 1) . "g`]"', { + expr = true, + replace_keycodes = false, + desc = "visually select changed text", +}) vim.keymap.set( - "n", - "gV", - '"g`[" . strpart(getregtype(), 0, 1) . "g`]"', - { expr = true, replace_keycodes = false, desc = "visually select changed text" } + "x", + "g/", + "/\\%V", + { desc = "search inside visual selection" } ) -vim.keymap.set("x", "g/", "/\\%V", { silent = false, desc = "search inside visual selection" }) --- [selection] -vim.keymap.set("o", ";", "iw", { desc = "select inside word" }) -vim.keymap.set("v", ";", "iw", { desc = "select inside word" }) +-- select inside word +vim.keymap.set({ "v", "o" }, ";", "iw") --- [edit] +-- editing vim.keymap.set({ "n", "v" }, "C", '"_c', { desc = "non-copy change" }) vim.keymap.set({ "n", "v" }, "D", '"_d', { desc = "non-copy delete" }) vim.keymap.set("o", "D", "0D", { desc = "clear current line" }) --- [quickfix] vim.keymap.set("n", "zq", function() - local is_qf_open = vim.iter(vim.api.nvim_tabpage_list_wins(0)):find(function(win) - local buf = vim.api.nvim_win_get_buf(win) - return vim.bo[buf].buftype == "quickfix" - end) + local is_qf_open = vim + .iter(vim.api.nvim_tabpage_list_wins(0)) + :find(function(win) + local buf = vim.api.nvim_win_get_buf(win) + return vim.bo[buf].buftype == "quickfix" + end) if is_qf_open then vim.cmd([[cclose]]) return @@ -67,7 +85,6 @@ vim.keymap.set("n", "zq", function() vim.cmd([[botright copen]]) end, { desc = "toggle quickfix" }) --- [diff] vim.keymap.set("n", "zD", function() if vim.o.diff then vim.cmd([[diffoff]]) @@ -76,63 +93,33 @@ vim.keymap.set("n", "zD", function() vim.cmd([[diffthis]]) end, { desc = "toggle diff mode" }) --- [treesitter] -- vim-scriptease inspired `zS` vim.keymap.set("n", "zS", vim.show_pos, { desc = "inspect marks" }) -local ns = vim.api.nvim_create_namespace("resize-mode") -vim.keymap.set("n", "w", function() - vim.on_key(function(key, typed) - local switch = { - [""] = function() - if vim.fn.winnr() == vim.fn.winnr("l") then - return vim.fn.win_move_separator(vim.fn.winnr("h"), -1) - end - vim.fn.win_move_separator(vim.fn.winnr(), -1) - end, - [""] = function() - if vim.fn.winnr() ~= vim.fn.winnr("j") then - vim.fn.win_move_statusline(vim.fn.winnr(), 1) - end - vim.fn.win_move_statusline(vim.fn.winnr("k"), 1) - end, - [""] = function() - if vim.fn.winnr() ~= vim.fn.winnr("j") then - vim.fn.win_move_statusline(vim.fn.winnr(), -1) - end - vim.fn.win_move_statusline(vim.fn.winnr("k"), -1) - end, - [""] = function() - if vim.fn.winnr() == vim.fn.winnr("l") then - return vim.fn.win_move_separator(vim.fn.winnr("h"), 1) - end - vim.fn.win_move_separator(vim.fn.winnr(), 1) - end, - } - - local k = vim.fn.keytrans(typed) - if k == "" then - vim.on_key(nil, ns) - elseif vim.tbl_contains({ "h", "j", "k", "l" }, k) then - vim.cmd.wincmd(k) - elseif vim.tbl_contains(vim.tbl_keys(switch), k) then - local fn = switch[k] - if fn and type(fn) == "function" then - fn() - end - end - return "" - end, ns) -end, { desc = "enter resize mode" }) - --- [editing] -vim.keymap.set("n", "g.", [[:%sno/"/./g]], { desc = "repeat last edit for file" }) +vim.keymap.set( + "n", + "g.", + [[:%sno/"/./g]], + { desc = "repeat last edit for file" } +) -vim.keymap.set("n", [[\c]], "setlocal cursorline! cursorline?", { desc = "toggle 'cursorline'" }) -vim.keymap.set("n", [[\C]], "setlocal cursorcolumn! cursorcolumn?", { desc = "toggle 'cursorcolumn'" }) +vim.keymap.set( + "n", + [[\c]], + "setlocal cursorline! cursorline?", + { desc = "toggle 'cursorline'" } +) +vim.keymap.set( + "n", + [[\C]], + "setlocal cursorcolumn! cursorcolumn?", + { desc = "toggle 'cursorcolumn'" } +) vim.keymap.set("n", [[\d]], function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) - print("diagnostics " .. (vim.diagnostic.is_enabled() and "enabled" or "disabled")) + print( + "diagnostics " .. (vim.diagnostic.is_enabled() and "enabled" or "disabled") + ) end, { desc = "toggle diagnostics" }) vim.keymap.set( "n", @@ -142,11 +129,32 @@ vim.keymap.set( ) vim.keymap.set("n", [[\i]], function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - print("inlay hint " .. (vim.lsp.inlay_hint.is_enabled() and "enabled" or "disabled")) + print( + "inlay hint " + .. (vim.lsp.inlay_hint.is_enabled() and "enabled" or "disabled") + ) end, { desc = "toggle inlay hint" }) -vim.keymap.set("n", [[\l]], "setlocal list! list?", { desc = "toggle 'list'" }) -vim.keymap.set("n", [[\r]], "setlocal relativenumber! relativenumber?", { desc = "toggle 'relativenumber'" }) -vim.keymap.set("n", [[\s]], "setlocal spell! spell?", { desc = "toggle 'spell'" }) -vim.keymap.set("n", [[\w]], "setlocal wrap! wrap?", { desc = "toggle 'wrap'" }) - -vim.keymap.set("n", "is", "(ivy-insert-section)") +vim.keymap.set( + "n", + [[\l]], + "setlocal list! list?", + { desc = "toggle 'list'" } +) +vim.keymap.set( + "n", + [[\r]], + "setlocal relativenumber! relativenumber?", + { desc = "toggle 'relativenumber'" } +) +vim.keymap.set( + "n", + [[\s]], + "setlocal spell! spell?", + { desc = "toggle 'spell'" } +) +vim.keymap.set( + "n", + [[\w]], + "setlocal wrap! wrap?", + { desc = "toggle 'wrap'" } +) diff --git a/config/plugin/keymap.insertsection.lua b/config/plugin/keymap.insertsection.lua index 6809eba..8da4b56 100644 --- a/config/plugin/keymap.insertsection.lua +++ b/config/plugin/keymap.insertsection.lua @@ -19,3 +19,5 @@ vim.keymap.set("n", "(ivy-insert-section)", function() vim.fn.cursor(vim.fn.line(".") + 1, inner_start) vim.cmd([[startreplace]]) end) + +vim.keymap.set("n", "is", "(ivy-insert-section)") diff --git a/config/plugin/keymap.resizemode.lua b/config/plugin/keymap.resizemode.lua new file mode 100644 index 0000000..6cead60 --- /dev/null +++ b/config/plugin/keymap.resizemode.lua @@ -0,0 +1,44 @@ +local ns = vim.api.nvim_create_namespace("resize-mode") +vim.keymap.set("n", "w", function() + vim.on_key(function(_, typed) + local switch = { + [""] = function() + if vim.fn.winnr() == vim.fn.winnr("l") then + return vim.fn.win_move_separator(vim.fn.winnr("h"), -1) + end + vim.fn.win_move_separator(vim.fn.winnr(), -1) + end, + [""] = function() + if vim.fn.winnr() ~= vim.fn.winnr("j") then + vim.fn.win_move_statusline(vim.fn.winnr(), 1) + end + vim.fn.win_move_statusline(vim.fn.winnr("k"), 1) + end, + [""] = function() + if vim.fn.winnr() ~= vim.fn.winnr("j") then + vim.fn.win_move_statusline(vim.fn.winnr(), -1) + end + vim.fn.win_move_statusline(vim.fn.winnr("k"), -1) + end, + [""] = function() + if vim.fn.winnr() == vim.fn.winnr("l") then + return vim.fn.win_move_separator(vim.fn.winnr("h"), 1) + end + vim.fn.win_move_separator(vim.fn.winnr(), 1) + end, + } + + local k = vim.fn.keytrans(typed) + if k == "" then + vim.on_key(nil, ns) + elseif vim.tbl_contains({ "h", "j", "k", "l" }, k) then + vim.cmd.wincmd(k) + elseif vim.tbl_contains(vim.tbl_keys(switch), k) then + local fn = switch[k] + if fn and type(fn) == "function" then + fn() + end + end + return "" + end, ns) +end, { desc = "enter resize mode" }) diff --git a/config/plugin/keymap.tether.lua b/config/plugin/keymap.tether.lua new file mode 100644 index 0000000..4ad4c8d --- /dev/null +++ b/config/plugin/keymap.tether.lua @@ -0,0 +1,4 @@ +-- select tether +vim.keymap.set("n", "ft", "(tether-select)") +-- select tether and stop current +vim.keymap.set("n", "fT", "Tether! select")