diff --git a/nvim/.config/nvim/lua/mappings.lua b/nvim/.config/nvim/lua/mappings.lua index 9e634d4..c7acad0 100644 --- a/nvim/.config/nvim/lua/mappings.lua +++ b/nvim/.config/nvim/lua/mappings.lua @@ -1,78 +1,96 @@ for _, mappings in pairs({ - -- {'n', '', ':w'}, - {'n', '', 'ZZ'}, -- write and exit from current buffer - {'n', 'Y', 'y$'}, -- do Y to yank till the end of the line - -- split and navigate to it - {'n', '', ':bn'}, - {'n', '', ':bp'}, - {'n', 's', ':split | wincmd j'}, - {'n', 'v', ':vsplit | wincmd l'}, - {'n', 'zl', 'zo'}, -- remap zl back to zo - -- replace selected - {'n', 'R', ':%s///gI'}, - -- if press 'a' no empty line it should respect indent - {'n', 'a', 'len(getline(\'.\')) == 0 ? \'S\' : \'a\'', {expr = true}}, - -- show last commands list on last item - {'n', 'Q', 'q:dd'}, - -- blink on next match - { - 'n', - 'n', - function() - vim.cmd('norm! nzz') - vim.opt.hlsearch = true - vim.defer_fn(function() vim.opt.hlsearch = false end, 200) - end, - {noremap = true, remap = true} - }, - { - 'n', - 'N', - function() - vim.cmd('norm! Nzz') - vim.opt.hlsearch = true - vim.defer_fn(function() vim.opt.hlsearch = false end, 200) - end, - {noremap = true, remap = true} - }, - { - 'n', - '*', - function() - vim.cmd('norm! *zz') - vim.opt.hlsearch = true - vim.defer_fn(function() vim.opt.hlsearch = false end, 200) - end, - {noremap = true, remap = true} - }, - -- do not yank on x/X - {'n', 'x', '"_dl'}, - {'n', 'X', '"_dh'}, - -- magic search mappnigs - {'n', '/', '/\\v', {noremap = true}}, - {'v', ':s/', ':s/\\v', {noremap = true}}, - {'c', '%s/', '%s/\\v', {noremap = true}}, - {'c', '%s/', '%s/\\v', {noremap = true}}, - { - 'n', - '', - function() - local word_under_cursor = vim.fn.expand('') - if word_under_cursor == 'true' then - vim.cmd('normal ciwfalse') - return - elseif word_under_cursor == 'false' then - vim.cmd('normal ciwtrue') - return - end - vim.cmd('normal! ') - end, - {noremap = true} - } + -- {'n', '', ':w'}, + { "n", "", "ZZ" }, -- write and exit from current buffer + { "n", "Y", "y$" }, -- do Y to yank till the end of the line + -- split and navigate to it + { "n", "", ":bn" }, + { "n", "", ":bp" }, + { "n", "s", ":split | wincmd j" }, + { "n", "v", ":vsplit | wincmd l" }, + { "n", "zl", "zo" }, -- remap zl back to zo + -- replace selected + { "n", "R", ":%s///gI" }, + -- if press 'a' no empty line it should respect indent + { "n", "a", "len(getline('.')) == 0 ? 'S' : 'a'", { expr = true } }, + -- show last commands list on last item + { "n", "Q", "q:dd" }, + -- blink on next match + { + "n", + "n", + function() + vim.cmd("norm! nzz") + vim.opt.hlsearch = true + vim.defer_fn(function() + vim.opt.hlsearch = false + end, 200) + end, + { noremap = true, remap = true }, + }, + { + "n", + "N", + function() + vim.cmd("norm! Nzz") + vim.opt.hlsearch = true + vim.defer_fn(function() + vim.opt.hlsearch = false + end, 200) + end, + { noremap = true, remap = true }, + }, + { + "n", + "*", + function() + vim.cmd("norm! *zz") + vim.opt.hlsearch = true + vim.defer_fn(function() + vim.opt.hlsearch = false + end, 200) + end, + { noremap = true, remap = true }, + }, + -- magic search mappnigs + { "n", "/", "/\\v", { noremap = true } }, + { "v", ":s/", ":s/\\v", { noremap = true } }, + { "c", "%s/", "%s/\\v", { noremap = true } }, + { "c", "%s/", "%s/\\v", { noremap = true } }, + { + "n", + "", + function() + local word_under_cursor = vim.fn.expand("") + if word_under_cursor == "true" then + vim.cmd("normal ciwfalse") + return + elseif word_under_cursor == "false" then + vim.cmd("normal ciwtrue") + return + end + vim.cmd("normal! ") + end, + { noremap = true }, + }, }) do - local mode = mappings[1] - local key = mappings[2] - local value = mappings[3] - local options = mappings[4] or {silent = true} - vim.keymap.set(mode, key, value, options) + local mode = mappings[1] + local key = mappings[2] + local value = mappings[3] + local options = mappings[4] or { silent = true } + vim.keymap.set(mode, key, value, options) +end + +-- Define modes and delete mappings to be replaced +local modes = { "n", "v" } +local delete_mappings = { + d = '"_d', + D = '"_D', + x = '"_x', + X = '"_X', +} +-- Iterate over the modes and set the new mappings +for _, mode in ipairs(modes) do + for lhs, rhs in pairs(delete_mappings) do + vim.keymap.set(mode, lhs, rhs, { noremap = true, silent = true }) + end end