refactor: keymap helper function

This commit is contained in:
Gustavo "Guz" L. de Mello
2024-03-15 22:22:26 -03:00
parent 5d55b90f46
commit 440115a087
3 changed files with 53 additions and 36 deletions

View File

@@ -28,6 +28,7 @@
"suda.vim": { "branch": "master", "commit": "8b0fc3711760195aba104e2d190cff9af8267052" },
"telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"tmux.nvim": { "branch": "main", "commit": "ea67d59721eb7e12144ce2963452e869bfd60526" },
"trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" },
"vim-fugitive": { "branch": "master", "commit": "59659093581aad2afacedc81f009ed6a4bfad275" },
"vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" },
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },

View File

@@ -1,54 +1,64 @@
local map = function(mode, keys, func, options)
if not options then options = {} end
if options.desc then options.desc = '[' .. keys .. '] ' .. options.desc end
vim.keymap.set(mode, keys, func, options);
end
-- Thank you ThePrimeagen ---------------
-- Move when highlighted
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv");
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv");
map('v', 'J', ":m '>+1<CR>gv=gv");
map('v', 'K', ":m '<-2<CR>gv=gv");
-- Make cursor stay in place when using J
vim.keymap.set('n', 'J', 'mzJ`z');
map('n', 'J', 'mzJ`z');
-- Make cursor stay in the middle when jumping
-- with ctrl+d and ctrl+u
vim.keymap.set('n', '<C-d>', '<C-d>zz');
vim.keymap.set('n', '<C-u>', '<C-u>zz');
map('n', '<C-d>', '<C-d>zz');
map('n', '<C-u>', '<C-u>zz');
-- Just to be sure, whatever
vim.keymap.set('n', '<C-c>', '<Esc>');
map('n', '<C-c>', '<Esc>');
-- Don't press Q
vim.keymap.set('n', 'Q', '<nop>');
map('n', 'Q', '<nop>');
-- Delete to the void
vim.keymap.set('n', '<leader>d', '\"_d');
vim.keymap.set('v', '<leader>d', '\"_d');
map('n', '<leader>d', '\"_d');
map('v', '<leader>d', '\"_d');
-- Replace current word in entire file
vim.keymap.set("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
map("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
-- Turn file into a Linux executable
vim.keymap.set('n', '<leader>x', '<cmd>!chmod +x %<CR>', { silent = true });
map('n', '<leader>x', '<cmd>!chmod +x %<CR>', { silent = true });
-- Harpoon -------------------------------
-- local harpoon = require('harpoon');
-- harpoon:setup();
-- --------------------------------------
vim.keymap.set('n', '<leader>w\\', '<cmd>:vsplit<cr>', { desc = '[w\\] Splits the window vertically' });
vim.keymap.set('n', '<leader>w/', '<cmd>:split<cr>', { desc = '[w/] Splits the window horizontally' });
map('n', '<leader>w\\', '<cmd>:vsplit<cr>', { desc = 'Splits the window vertically' });
map('n', '<leader>w/', '<cmd>:split<cr>', { desc = 'Splits the window horizontally' });
vim.keymap.set('n', '<leader>e', '<cmd>:Ex<cr>', { desc = '[e] Explorer' });
map('n', '<leader>e', '<cmd>:Ex<cr>', { desc = 'Explorer' });
vim.keymap.set('n', 's=', 'z=', { desc = '[s=] Suggest spelling correction' });
vim.keymap.set('n', '<leader>st', function()
map('n', 's=', 'z=', { desc = 'Suggest spelling correction' });
map('n', '<leader>st', function()
if vim.o.spell then
vim.o.spell = false;
else
vim.o.spell = true;
end
end, { desc = '[st] Toggle spelling correction' });
end, { desc = 'Toggle spelling correction' });
vim.keymap.set('n', '<leader>ee', vim.diagnostic.open_float, { desc = '[ee] Open diagnostic' });
map('n', '<leader>ee', vim.diagnostic.open_float, { desc = 'Open diagnostic' });
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true });
map({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true });
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true });
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true });
map('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true });
map('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true });

View File

@@ -95,6 +95,26 @@ return {
opts = {},
lazy = false,
},
{
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = {
'nvim-lua/plenary.nvim',
{
'nvim-telescope/telescope-fnf-native.nvim',
build = 'make',
cond = function()
return vim.fn.executable('make') == 1
end
},
},
},
-- Do no why I can't clone it via lazy.nvim
--[[ {
'ThePrimeagen/harpoon',
branch = 'harpoon2',
dependencies = { 'nvim-lua/plenary.nvim', },
}, ]]
{
'stevearc/conform.nvim',
opts = {
@@ -121,20 +141,6 @@ return {
},
},
},
{
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = {
'nvim-lua/plenary.nvim',
{
'nvim-telescope/telescope-fnf-native.nvim',
build = 'make',
cond = function()
return vim.fn.executable('make') == 1
end
},
},
},
{
'okuuva/auto-save.nvim',
lazy = false,