From c3c83a0bec57fafb88c7fb718c9e51c7f500420c Mon Sep 17 00:00:00 2001 From: Neeraj A Date: Sun, 8 Oct 2023 11:51:49 +0530 Subject: [PATCH] last updates --- init.lua | 2 +- lua/custom/plugins/gitsigns.lua | 57 ++++++++++++++++++++++----------- lua/custom/plugins/spectre.lua | 21 ++++++++++++ 3 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 lua/custom/plugins/spectre.lua diff --git a/init.lua b/init.lua index a85905ee..ae9547f1 100644 --- a/init.lua +++ b/init.lua @@ -76,7 +76,7 @@ require('lazy').setup({ -- Useful status updates for LSP -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, + { 'j-hui/fidget.nvim', opts = {}, branch = 'legacy' }, -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua index 91985a23..b622501f 100644 --- a/lua/custom/plugins/gitsigns.lua +++ b/lua/custom/plugins/gitsigns.lua @@ -30,27 +30,46 @@ return { }, numhl = true, linehl = false, - keymaps = { - -- Default keymap options - noremap = true, - buffer = true, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns - ['n hn'] = { - expr = true, - "&diff ? 'hn' : 'lua require\"gitsigns\".next_hunk()'" - }, - ['n hN'] = { - expr = true, - "&diff ? 'hN' : 'lua require\"gitsigns\".prev_hunk()'" - }, + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end - ['n hs'] = 'lua require"gitsigns".stage_hunk()', - ['n hu'] = 'lua require"gitsigns".undo_stage_hunk()', - ['n hr'] = 'lua require"gitsigns".reset_hunk()', - ['n hR'] = 'lua require"gitsigns".reset_buffer()', - ['n hp'] = 'lua require"gitsigns".preview_hunk()', - ['n hb'] = 'lua require"gitsigns".blame_line()' - }, + -- Navigation + map('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, {expr=true}) + + map('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, {expr=true}) + + -- Actions + map('n', 'hs', gs.stage_hunk) + map('n', 'hr', gs.reset_hunk) + map('v', 'hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('v', 'hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', 'hp', gs.preview_hunk) + map('n', 'hb', function() gs.blame_line{full=true} end) + map('n', 'tb', gs.toggle_current_line_blame) + map('n', 'hd', gs.diffthis) + map('n', 'hD', function() gs.diffthis('~') end) + map('n', 'td', gs.toggle_deleted) + + -- Text object + map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + end, watch_gitdir = {interval = 1000}, current_line_blame = true, sign_priority = 6, diff --git a/lua/custom/plugins/spectre.lua b/lua/custom/plugins/spectre.lua new file mode 100644 index 00000000..2bfa11a4 --- /dev/null +++ b/lua/custom/plugins/spectre.lua @@ -0,0 +1,21 @@ +return { + 'nvim-pack/nvim-spectre', + requires = { + 'nvim-lua/plenary.nvim' -- optional, for file icons + }, + config = function() + vim.keymap.set('n', 'S', 'lua require("spectre").toggle()', { + desc = "Toggle Spectre" + }) + vim.keymap.set('n', 'sw', 'lua require("spectre").open_visual({select_word=true})', { + desc = "Search current word" + }) + vim.keymap.set('v', 'sw', 'lua require("spectre").open_visual()', { + desc = "Search current word" + }) + vim.keymap.set('n', 'sp', 'lua require("spectre").open_file_search({select_word=true})', { + desc = "Search on current file" + }) + end +} +