mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-07 21:45:59 +01:00
feat: add gitsigns keybindings
This commit is contained in:
parent
f3061949b6
commit
4adb03cd1d
2 changed files with 73 additions and 37 deletions
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
|
@ -7,40 +6,62 @@
|
||||||
with lib;
|
with lib;
|
||||||
with builtins; let
|
with builtins; let
|
||||||
cfg = config.vim.git;
|
cfg = config.vim.git;
|
||||||
|
|
||||||
|
self = import ./git.nix {inherit lib;};
|
||||||
|
gsMappingDefinitions = self.options.vim.git.gitsigns.mappings;
|
||||||
|
|
||||||
|
gsMappings = addDescriptionsToMappings cfg.gitsigns.mappings gsMappingDefinitions;
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
(mkIf cfg.gitsigns.enable (mkMerge [
|
(mkIf cfg.gitsigns.enable (mkMerge [
|
||||||
{
|
{
|
||||||
vim.startPlugins = ["gitsigns-nvim"];
|
vim.startPlugins = ["gitsigns-nvim"];
|
||||||
|
|
||||||
|
vim.maps.normal = mkMerge [
|
||||||
|
(mkSetExprBinding gsMappings.nextHunk ''
|
||||||
|
function()
|
||||||
|
if vim.wo.diff then return ${toJSON gsMappings.nextHunk.value} end
|
||||||
|
|
||||||
|
vim.schedule(function() package.loaded.gitsigns.next_hunk() end)
|
||||||
|
|
||||||
|
return '<Ignore>'
|
||||||
|
end
|
||||||
|
'')
|
||||||
|
(mkSetExprBinding gsMappings.previousHunk ''
|
||||||
|
function()
|
||||||
|
if vim.wo.diff then return ${toJSON gsMappings.previousHunk.value} end
|
||||||
|
|
||||||
|
vim.schedule(function() package.loaded.gitsigns.prev_hunk() end)
|
||||||
|
|
||||||
|
return '<Ignore>'
|
||||||
|
end
|
||||||
|
'')
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.stageHunk "package.loaded.gitsigns.stage_hunk")
|
||||||
|
(mkSetLuaBinding gsMappings.resetHunk "package.loaded.gitsigns.reset_hunk")
|
||||||
|
(mkSetLuaBinding gsMappings.undoStageHunk "package.loaded.gitsigns.undo_stage_hunk")
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.stageBuffer "package.loaded.gitsigns.stage_buffer")
|
||||||
|
(mkSetLuaBinding gsMappings.resetBuffer "package.loaded.gitsigns.reset_buffer")
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.previewHunk "package.loaded.gitsigns.preview_hunk")
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.blameLine "function() package.loaded.gitsigns.blame_line{full=true} end")
|
||||||
|
(mkSetLuaBinding gsMappings.toggleBlame "package.loaded.gitsigns.toggle_current_line_blame")
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.diffThis "package.loaded.gitsigns.diffthis")
|
||||||
|
(mkSetLuaBinding gsMappings.diffProject "function() package.loaded.gitsigns.diffthis('~') end")
|
||||||
|
|
||||||
|
(mkSetLuaBinding gsMappings.toggleDeleted "package.loaded.gitsigns.toggle_deleted")
|
||||||
|
];
|
||||||
|
|
||||||
|
vim.maps.visual = mkMerge [
|
||||||
|
(mkSetLuaBinding gsMappings.stageHunk "function() package.loaded.gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end")
|
||||||
|
(mkSetLuaBinding gsMappings.resetHunk "function() package.loaded.gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end")
|
||||||
|
];
|
||||||
|
|
||||||
vim.luaConfigRC.gitsigns = nvim.dag.entryAnywhere ''
|
vim.luaConfigRC.gitsigns = nvim.dag.entryAnywhere ''
|
||||||
require('gitsigns').setup {
|
require('gitsigns').setup{}
|
||||||
keymaps = {
|
|
||||||
noremap = true,
|
|
||||||
|
|
||||||
['n <leader>gn'] = { expr = true, "&diff ? \'\' : '<cmd>Gitsigns next_hunk<CR>'"},
|
|
||||||
['n <leader>gp'] = { expr = true, "&diff ? \'\' : '<cmd>Gitsigns prev_hunk<CR>'"},
|
|
||||||
|
|
||||||
['n <leader>gs'] = '<cmd>Gitsigns stage_hunk<CR>',
|
|
||||||
['v <leader>gs'] = ':Gitsigns stage_hunk<CR>',
|
|
||||||
['n <leader>gu'] = '<cmd>Gitsigns undo_stage_hunk<CR>',
|
|
||||||
['n <leader>gr'] = '<cmd>Gitsigns reset_hunk<CR>',
|
|
||||||
['v <leader>gr'] = ':Gitsigns reset_hunk<CR>',
|
|
||||||
['n <leader>gR'] = '<cmd>Gitsigns reset_buffer<CR>',
|
|
||||||
['n <leader>gp'] = '<cmd>Gitsigns preview_hunk<CR>',
|
|
||||||
['n <leader>gb'] = '<cmd>lua require"gitsigns".blame_line{full=true}<CR>',
|
|
||||||
['n <leader>gS'] = '<cmd>Gitsigns stage_buffer<CR>',
|
|
||||||
['n <leader>gU'] = '<cmd>Gitsigns reset_buffer_index<CR>',
|
|
||||||
['n <leader>gts'] = ':Gitsigns toggle_signs<CR>',
|
|
||||||
['n <leader>gtn'] = ':Gitsigns toggle_numhl<CR>',
|
|
||||||
['n <leader>gtl'] = ':Gitsigns toggle_linehl<CR>',
|
|
||||||
['n <leader>gtw'] = ':Gitsigns toggle_word_diff<CR>',
|
|
||||||
|
|
||||||
-- Text objects
|
|
||||||
['o ih'] = ':<C-U>Gitsigns select_hunk<CR>',
|
|
||||||
['x ih'] = ':<C-U>Gitsigns select_hunk<CR>'
|
|
||||||
},
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
{
|
{lib, ...}:
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
with lib;
|
||||||
with builtins; let
|
with builtins; {
|
||||||
cfg = config.vim.git;
|
|
||||||
in {
|
|
||||||
options.vim.git = {
|
options.vim.git = {
|
||||||
enable = mkEnableOption "Git support";
|
enable = mkEnableOption "Git support";
|
||||||
|
|
||||||
gitsigns = {
|
gitsigns = {
|
||||||
enable = mkEnableOption "gitsigns";
|
enable = mkEnableOption "gitsigns";
|
||||||
|
|
||||||
|
mappings = {
|
||||||
|
nextHunk = mkMappingOption "Next hunk [Gitsigns]" "]c";
|
||||||
|
previousHunk = mkMappingOption "Previous hunk [Gitsigns]" "[c";
|
||||||
|
|
||||||
|
stageHunk = mkMappingOption "Stage hunk [Gitsigns]" "<leader>hs";
|
||||||
|
undoStageHunk = mkMappingOption "Undo stage hunk [Gitsigns]" "<leader>hu";
|
||||||
|
resetHunk = mkMappingOption "Reset hunk [Gitsigns]" "<leader>hr";
|
||||||
|
|
||||||
|
stageBuffer = mkMappingOption "Stage buffer [Gitsigns]" "<leader>hS";
|
||||||
|
resetBuffer = mkMappingOption "Reset buffer [Gitsigns]" "<leader>hR";
|
||||||
|
|
||||||
|
previewHunk = mkMappingOption "Preview hunk [Gitsigns]" "<leader>hP";
|
||||||
|
|
||||||
|
blameLine = mkMappingOption "Blame line [Gitsigns]" "<leader>hb";
|
||||||
|
toggleBlame = mkMappingOption "Toggle blame [Gitsigns]" "<leader>tb";
|
||||||
|
|
||||||
|
diffThis = mkMappingOption "Diff this [Gitsigns]" "<leader>hd";
|
||||||
|
diffProject = mkMappingOption "Diff project [Gitsigns]" "<leader>hD";
|
||||||
|
|
||||||
|
toggleDeleted = mkMappingOption "Toggle deleted [Gitsigns]" "<leader>td";
|
||||||
|
};
|
||||||
|
|
||||||
codeActions = mkEnableOption "gitsigns codeactions through null-ls";
|
codeActions = mkEnableOption "gitsigns codeactions through null-ls";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue