From 0261c07d0a41bd65d51a85aa8d832491465a7589 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 17 Apr 2024 10:54:02 +0700 Subject: [PATCH] chore(nvim): Converted normal command shortcut to Lua --- .config/nvim/lua/null/remap.lua | 37 ++++++++++++++++++++------------- .config/vim/vim_uni | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.config/nvim/lua/null/remap.lua b/.config/nvim/lua/null/remap.lua index 1c0f3d8..027c659 100644 --- a/.config/nvim/lua/null/remap.lua +++ b/.config/nvim/lua/null/remap.lua @@ -1,23 +1,32 @@ -- Loaded by `null.config` -local remap = function(mode, key, target, opts) - vim.api.nvim_set_keymap(mode, key, target, opts or { - noremap = true, - silent = true, - }) +local map = function(modes, key, target, opts) + local mt = {} + + for mode in modes:gmatch"." do + table.insert(mt, mode) + end + + vim.keymap.set(mt, key, target, opts or { + noremap = true, + silent = true, + }) end -- Map Ctrl+U as U so it can be used as redo -remap("n", "", "U") +map("n", "", "U") -- Map U as redo -remap("n", "U", "") +map("n", "U", "") -- Yank and Put -remap("n", "", '"+y') -remap("n", "", '"+p') -remap("n", "", '"+y') -remap("n", "", '"+p') +map("n", "", '"+y') +map("n", "", '"+p') +map("n", "", '"+y') +map("n", "", '"+p') -- Comment a line like how it is on VSC (using vim-commentary) -remap("n", "", "gcc", { noremap = false }) -remap("v", "", "gc", { noremap = false }) -remap("i", "", "gcc", { noremap = false }) +map("n", "", "gcc", { remap = true }) +map("v", "", "gc", { remap = true }) +map("i", "", "gcc", { remap = true }) + +-- Normal command shortcut for VISUAL mode +map("v", ".", ":normal .") diff --git a/.config/vim/vim_uni b/.config/vim/vim_uni index b486137..94244b0 100644 --- a/.config/vim/vim_uni +++ b/.config/vim/vim_uni @@ -37,7 +37,7 @@ set foldlevel=1 autocmd FileType python setlocal foldmethod=indent " ----- Mapping -" Norm but in shortcut +" Norm but in shortcut -- converted vnoremap . :normal . " Map ctrl + u as U -- converted