From 370bbf0edff9381823ab999358ef5518cb58cc73 Mon Sep 17 00:00:00 2001 From: leafee98 Date: Mon, 22 May 2023 09:56:32 +0800 Subject: [PATCH] add keymap setup for gitsign, modify README --- README.md | 4 ++++ lua/plugins/10-editor.lua | 7 ------ lua/plugins/20-git.lua | 43 +++++++++++++++++++++++++++++++++++ lua/plugins/50-treesitter.lua | 1 - 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 lua/plugins/20-git.lua diff --git a/README.md b/README.md index 7ba9283..dfe2746 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,7 @@ Here is my config of neovim. ## Usage Just clone this repository into directory `~/.config/nvim/` and start neovim. [lazy.nvim](https://github.com/folke/lazy.nvim) will auto install itself and other plugins at startup. + +``` +git clone ~/.config/nvim +``` diff --git a/lua/plugins/10-editor.lua b/lua/plugins/10-editor.lua index cbcc3c4..c3dc0ce 100644 --- a/lua/plugins/10-editor.lua +++ b/lua/plugins/10-editor.lua @@ -10,23 +10,16 @@ return { { "karb94/neoscroll.nvim", main = "neoscroll", - config = true, opts = { }, }, { "lukas-reineke/indent-blankline.nvim", main = "indent_blankline", - config = true, opts = { show_current_context = true, show_current_context_start = true, }, }, - { - "lewis6991/gitsigns.nvim", - main = "gitsigns", - opts = { }, - }, { "akinsho/bufferline.nvim", main = "bufferline", diff --git a/lua/plugins/20-git.lua b/lua/plugins/20-git.lua new file mode 100644 index 0000000..12fb3be --- /dev/null +++ b/lua/plugins/20-git.lua @@ -0,0 +1,43 @@ +return { + "lewis6991/gitsigns.nvim", + main = "gitsigns", + opts = { + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + local function m(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + m("n", "]c", function() + if vim.wo.diff then return "]c" end + vim.schedule(function() gs.next_hunk() end) + return "" + end, {expr=true}) + + m('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, {expr=true}) + + m('n', 'hs', gs.stage_hunk) + m('n', 'hr', gs.reset_hunk) + m('v', 'hs', function() gs.stage_hunk {vim.fn.line("."), vim.fn.line("v")} end) + m('v', 'hr', function() gs.reset_hunk {vim.fn.line("."), vim.fn.line("v")} end) + m('n', 'hS', gs.stage_buffer) + m('n', 'hu', gs.undo_stage_hunk) + m('n', 'hR', gs.reset_buffer) + m('n', 'hp', gs.preview_hunk) + m('n', 'hb', function() gs.blame_line{full=true} end) + m('n', 'tb', gs.toggle_current_line_blame) + m('n', 'hd', gs.diffthis) + m('n', 'hD', function() gs.diffthis('~') end) + m('n', 'td', gs.toggle_deleted) + end, + }, + config = function (lazyplug, opts) + require(lazyplug.main).setup(opts) + end, +} diff --git a/lua/plugins/50-treesitter.lua b/lua/plugins/50-treesitter.lua index e23739e..02227a6 100644 --- a/lua/plugins/50-treesitter.lua +++ b/lua/plugins/50-treesitter.lua @@ -1,7 +1,6 @@ return { "nvim-treesitter/nvim-treesitter", main = "nvim-treesitter.configs", - config = true, build = ":TSUpdate", opts = { indent = { enable = true },