From d89d00af713da180f2511dc0af005756f449df7e Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Wed, 3 Jan 2024 02:10:43 +0100 Subject: [PATCH] test gitsigns ... --- lua/keymappings.lua | 3 +-- lua/plugins/gitsigns.lua | 42 ++++++++++++++++++++++++++++++++++++++++ lua/plugins/init.lua | 3 ++- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lua/plugins/gitsigns.lua diff --git a/lua/keymappings.lua b/lua/keymappings.lua index d85412f..d56d803 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -8,9 +8,8 @@ utils.map("n", "", "bn") utils.map("n", "", "bp") -- Turn spellchecker on -utils.map("n", "s", "setlocal spell spelllang=en_us") +utils.map("n", "se", "setlocal spell spelllang=en_us") -- Toggle line numbers and file tree utils.map("n", "", "set nonumber!") utils.map("n", "fe", "Oil") -utils.map("n", "ca", "CodeActionMenu") diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..6a4f422 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,42 @@ +require('gitsigns').setup { + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- 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 +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index f9816a1..9618355 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -28,7 +28,6 @@ require('packer').startup(function() } -- Statusbar, colors and syntax - use { 'jacoborus/tender.vim' } use { 'nvim-treesitter/nvim-treesitter' } use { 'vim-airline/vim-airline' } use { 'vim-airline/vim-airline-themes' } @@ -52,6 +51,7 @@ require('packer').startup(function() { "sindrets/diffview.nvim" }, }, } + use { "lewis6991/gitsigns.nvim" } -- Filesystem in a nvim buffer use { 'stevearc/oil.nvim' } @@ -63,6 +63,7 @@ require('packer').startup(function() end) require('plugins.cmp') +require('plugins.gitsigns') require('plugins.neogit') require('plugins.oil') require('plugins.treesitter')