chore(nvim): Converted normal command shortcut to Lua

This commit is contained in:
Ahmad Ansori Palembani 2024-04-17 10:54:02 +07:00
parent b9c32dfd52
commit 0261c07d0a
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 24 additions and 15 deletions

View file

@ -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", "<C-u>", "U")
map("n", "<C-u>", "U")
-- Map U as redo
remap("n", "U", "<C-r>")
map("n", "U", "<C-r>")
-- Yank and Put
remap("n", "<C-y>", '"+y')
remap("n", "<C-p>", '"+p')
remap("n", "<C-Y>", '"+y')
remap("n", "<C-P>", '"+p')
map("n", "<C-y>", '"+y')
map("n", "<C-p>", '"+p')
map("n", "<C-Y>", '"+y')
map("n", "<C-P>", '"+p')
-- Comment a line like how it is on VSC (using vim-commentary)
remap("n", "<C-/>", "gcc", { noremap = false })
remap("v", "<C-/>", "gc", { noremap = false })
remap("i", "<C-/>", "<esc>gcc", { noremap = false })
map("n", "<C-/>", "gcc", { remap = true })
map("v", "<C-/>", "gc", { remap = true })
map("i", "<C-/>", "<esc>gcc", { remap = true })
-- Normal command shortcut for VISUAL mode
map("v", ".", ":normal .<CR>")