From e874755fd9c6076209f90aa9ef91fb26794364b0 Mon Sep 17 00:00:00 2001 From: Szwendacz99 Date: Sat, 12 Nov 2022 12:41:55 +0100 Subject: [PATCH] Switch git gutter plugin to gitsigns, add scrollbar, hlslens --- README.md | 2 - init.vim | 9 +++-- lua/general.lua | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e3f1e79..4baee93 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug. https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' ``` -##### - ##### Inside vim diff --git a/init.vim b/init.vim index 45c53a5..313885b 100644 --- a/init.vim +++ b/init.vim @@ -15,13 +15,15 @@ Plug 'mfussenegger/nvim-lint' Plug 'onsails/lspkind.nvim' " various plugins +Plug 'lewis6991/gitsigns.nvim' +Plug 'petertriho/nvim-scrollbar' +Plug 'kevinhwang91/nvim-hlslens' Plug 'windwp/nvim-ts-autotag' Plug 'hrsh7th/cmp-path' -Plug 'L3MON4D3/LuaSnip', {'tag': 'v1.*'} +Plug 'L3MON4D3/LuaSnip', {'tag': '*'} Plug 'saadparwaiz1/cmp_luasnip' Plug 'lambdalisue/suda.vim' -Plug 'airblade/vim-gitgutter' -Plug 'akinsho/bufferline.nvim', { 'tag': 'v3.*' } +Plug 'akinsho/bufferline.nvim', { 'tag': '*' } Plug 'gorbit99/codewindow.nvim' Plug 'preservim/nerdcommenter' Plug 'rmagatti/auto-session' @@ -32,7 +34,6 @@ Plug 'vmware-archive/salt-vim' Plug 'nvim-lualine/lualine.nvim' Plug 'itchyny/vim-cursorword' Plug 'sheerun/vim-polyglot' -Plug 'f-person/git-blame.nvim' " themes Plug 'navarasu/onedark.nvim' diff --git a/lua/general.lua b/lua/general.lua index cb89fef..04e45bd 100644 --- a/lua/general.lua +++ b/lua/general.lua @@ -1,3 +1,105 @@ +require("scrollbar").setup() + +-- hlslens config +require('hlslens').setup() + +local kopts = { noremap = true, silent = true } + +vim.api.nvim_set_keymap('n', 'n', + [[execute('normal! ' . v:count1 . 'n')lua require('hlslens').start()]], + kopts) +vim.api.nvim_set_keymap('n', 'N', + [[execute('normal! ' . v:count1 . 'N')lua require('hlslens').start()]], + kopts) +vim.api.nvim_set_keymap('n', '*', [[*lua require('hlslens').start()]], kopts) +vim.api.nvim_set_keymap('n', '#', [[#lua require('hlslens').start()]], kopts) +vim.api.nvim_set_keymap('n', 'g*', [[g*lua require('hlslens').start()]], kopts) +vim.api.nvim_set_keymap('n', 'g#', [[g#lua require('hlslens').start()]], kopts) + +vim.api.nvim_set_keymap('n', 'l', ':noh', kopts) + +-- config gitsigns +require('gitsigns').setup { + signs = { + add = { hl = 'GitSignsAdd', text = '│', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' }, + change = { hl = 'GitSignsChange', text = '│', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, + delete = { hl = 'GitSignsDelete', text = '_', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, + topdelete = { hl = 'GitSignsDelete', text = '‾', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, + changedelete = { hl = 'GitSignsChange', text = '~', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, + untracked = { hl = 'GitSignsAdd', text = '┆', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter = ', - ', + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + yadm = { + enable = false + }, + 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', 'v' }, 'hs', ':Gitsigns stage_hunk') + map({ 'n', 'v' }, 'hr', ':Gitsigns reset_hunk') + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', '', 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 +} + require('lualine').setup { options = { icons_enabled = true,