From 06404a4568f783221bb8cb8db9f6ad91f500a77c Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sat, 3 Feb 2024 02:28:45 -0600 Subject: refactor: git/telescope keymaps --- lua/plugins/gitsigns.lua | 25 +++++++++++++++++++------ lua/plugins/telescope.lua | 15 ++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'lua') diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua index 086fb91..a40a3dc 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/gitsigns.lua @@ -1,18 +1,31 @@ return { 'lewis6991/gitsigns.nvim', opts = { - signs = { + signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, - on_attach = function(bufnr) - local gitsigns = require('gitsigns') - vim.keymap.set('n', '[c', gitsigns.prev_hunk, { buffer = bufnr, desc = 'Go to Previous Hunk' }) - vim.keymap.set('n', ']c', gitsigns.next_hunk, { buffer = bufnr, desc = 'Go to Next Hunk' }) - vim.keymap.set('n', 'ph', gitsigns.preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = true, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + on_attach = function(bufnr) + local gs = require('gitsigns') + + -- TODO: use this function for most of the keymaps across plugins? + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + map('n', 'gp', gs.prev_hunk, { desc = '[g]it: [p]revious hunk' }) + map('n', 'gn', gs.next_hunk, { desc = '[g]it: [n]ext hunk' }) + map('n', 'gv', gs.preview_hunk, { desc = '[g]it: [v]iew hunk' }) + map('n', 'gb', gs.toggle_current_line_blame, { desc = '[g]it: [b]lame toggle' }) end, }, } diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 60084fb..7bb8ccf 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -35,12 +35,13 @@ return { previewer = false, }) end, { desc = '[/] Fuzzily search in current buffer' }) - vim.keymap.set('n', 'gf', ts_builtin.git_files, { desc = 'Search [G]it [F]iles' }) - vim.keymap.set('n', 'sf', ts_builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'sh', ts_builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sw', ts_builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', ts_builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', ts_builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', ts_builtin.lsp_references, { desc = '[S]earch [R]eferences' }) + vim.keymap.set('n', 'gf', ts_builtin.git_files, { desc = '[g]it: search [f]iles' }) + + vim.keymap.set('n', 'sf', ts_builtin.find_files, { desc = '[s]earch [f]iles' }) + vim.keymap.set('n', 'sh', ts_builtin.help_tags, { desc = '[s]earch [h]elp' }) + vim.keymap.set('n', 'sw', ts_builtin.grep_string, { desc = '[s]earch current [w]ord' }) + vim.keymap.set('n', 'sg', ts_builtin.live_grep, { desc = '[s]earch by [g]rep' }) + vim.keymap.set('n', 'sd', ts_builtin.diagnostics, { desc = '[s]earch [d]iagnostics' }) + vim.keymap.set('n', 'sr', ts_builtin.lsp_references, { desc = '[s]earch [r]eferences' }) end, } -- cgit v1.2.3-70-g09d2