Compare commits

...

2 commits

Author SHA1 Message Date
leafee98 df5be57d75 all gitsigns use h as key prefix 2023-05-22 09:59:06 +08:00
leafee98 370bbf0edf add keymap setup for gitsign, modify README 2023-05-22 09:56:32 +08:00
4 changed files with 47 additions and 8 deletions

View file

@ -5,3 +5,7 @@ Here is my config of neovim.
## Usage ## 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. 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 <url of this repo> ~/.config/nvim
```

View file

@ -10,23 +10,16 @@ return {
{ {
"karb94/neoscroll.nvim", "karb94/neoscroll.nvim",
main = "neoscroll", main = "neoscroll",
config = true,
opts = { }, opts = { },
}, },
{ {
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
main = "indent_blankline", main = "indent_blankline",
config = true,
opts = { opts = {
show_current_context = true, show_current_context = true,
show_current_context_start = true, show_current_context_start = true,
}, },
}, },
{
"lewis6991/gitsigns.nvim",
main = "gitsigns",
opts = { },
},
{ {
"akinsho/bufferline.nvim", "akinsho/bufferline.nvim",
main = "bufferline", main = "bufferline",

43
lua/plugins/20-git.lua Normal file
View file

@ -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", "]h", function()
if vim.wo.diff then return "]c" end
vim.schedule(function() gs.next_hunk() end)
return "<Ignore>"
end, {expr=true})
m('n', '[h', function()
if vim.wo.diff then return '[c' end
vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>'
end, {expr=true})
m('n', '<leader>hs', gs.stage_hunk)
m('n', '<leader>hr', gs.reset_hunk)
m('v', '<leader>hs', function() gs.stage_hunk {vim.fn.line("."), vim.fn.line("v")} end)
m('v', '<leader>hr', function() gs.reset_hunk {vim.fn.line("."), vim.fn.line("v")} end)
m('n', '<leader>hS', gs.stage_buffer)
m('n', '<leader>hu', gs.undo_stage_hunk)
m('n', '<leader>hR', gs.reset_buffer)
m('n', '<leader>hp', gs.preview_hunk)
m('n', '<leader>hb', function() gs.blame_line{full=true} end)
m('n', '<leader>tb', gs.toggle_current_line_blame)
m('n', '<leader>hd', gs.diffthis)
m('n', '<leader>hD', function() gs.diffthis('~') end)
m('n', '<leader>td', gs.toggle_deleted)
end,
},
config = function (lazyplug, opts)
require(lazyplug.main).setup(opts)
end,
}

View file

@ -1,7 +1,6 @@
return { return {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
main = "nvim-treesitter.configs", main = "nvim-treesitter.configs",
config = true,
build = ":TSUpdate", build = ":TSUpdate",
opts = { opts = {
indent = { enable = true }, indent = { enable = true },