Skip to content

Commit

Permalink
set up whichkey group names
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Mar 31, 2024
1 parent 16cb3c7 commit b87a2e5
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 27 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions modules/comments/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ with lib;

let
cfg = config.vim.comments;
keys = config.vim.keys.whichKey;
in
{
options.vim.comments = {
Expand Down Expand Up @@ -32,6 +33,14 @@ in
})
''
}
${writeIf keys.enable ''
wk.register({
["<leader>c"] = {
name = "Commenter",
},
})
''}
'';
};
}
9 changes: 9 additions & 0 deletions modules/filetree/nvimtreelua.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.filetree.nvimTreeLua;
keys = config.vim.keys.whichKey;
in
{
options.vim.filetree.nvimTreeLua = {
Expand Down Expand Up @@ -181,6 +182,14 @@ in
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
''}
${writeIf keys.enable ''
wk.register({
["<leader>t"] = {
name = "Tree & Todo",
},
})
''}
'';
};
}
49 changes: 32 additions & 17 deletions modules/git/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.git;
keys = config.vim.keys.whichKey;
in
{
options.vim.git = {
Expand Down Expand Up @@ -38,32 +39,46 @@ in
end
-- Navigation
map('n', '<leader>gn', function()
local function nextHunk()
if vim.wo.diff then return ']c' end
vim.schedule(function() gs.next_hunk() end)
return '<Ignore>'
end, {expr=true})
end
map('n', '<leader>gp', function()
local function prevHunk()
if vim.wo.diff then return '[c' end
vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>'
end, {expr=true})
end
local function stageHunk()
gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')}
end
local function resetHunk()
gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')}
end
-- Actions
map('n', '<leader>gs', gs.stage_hunk)
map('n', '<leader>gr', gs.reset_hunk)
map('v', '<leader>gs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('v', '<leader>gr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('n', '<leader>gS', gs.stage_buffer)
map('n', '<leader>gu', gs.undo_stage_hunk)
map('n', '<leader>gR', gs.reset_buffer)
map('n', '<leader>gp', gs.preview_hunk)
map('n', '<leader>gb', function() gs.blame_line{full=true} end)
map('n', '<leader>gtb', gs.toggle_current_line_blame)
map('n', '<leader>gd', gs.diffthis)
map('n', '<leader>gD', function() gs.diffthis('~') end)
map('n', '<leader>gtd', gs.toggle_deleted)
${writeIf keys.enable ''
wk.register({
["<leader>g"] = {
name = "Gitsigns",
b = { function() gs.blame_line{full=true} end, "Blame (full)" },
tb = { gs.toggle_current_line_blame, "Toggle blame" },
td = { gs.toggle_deleted, "Toggle deleted" },
d = { gs.diffthis, "Diff current file" },
D = { function() gs.diffthis('~') end, "Diff file" },
n = { nextHunk(), "Next hunk" },
p = { prevHunk(), "Previous hunk" },
r = { resetHunk(), "Reset hunk" },
s = { stageHunk(), "Stage hunk" },
S = { gs.stage_buffer, "Stage buffer" },
u = { gs.undo_stage_hunk, "Undo stage hunk" },
R = { gs.reset_buffer, "Reset buffer" },
},
})
''}
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
Expand Down
24 changes: 19 additions & 5 deletions modules/lsp/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.lsp;
keys = config.vim.keys.whichKey;
in
{
options.vim.lsp = {
Expand Down Expand Up @@ -91,11 +92,6 @@ in
(withPlugins cfg.folds [ promise-async nvim-ufo ]) ++
(withPlugins cfg.rust.enable [ crates-nvim rust-tools ]);

vim.nnoremap = withAttrSet cfg.scala.enable {
"<silent> <leader>ws" = "<cmd>lua require'metals'.worksheet_hover()<CR>";
"<silent> <leader>ad" = "<cmd>lua require'metals'.open_all_diagnostics()<CR>";
};

vim.configRC = ''
${writeIf cfg.rust.enable ''
function! MapRustTools()
Expand Down Expand Up @@ -247,6 +243,24 @@ in
''
};
${writeIf keys.enable ''
wk.register({
["<leader>l"] = {
name = "LSP",
},
})
${writeIf cfg.scala.enable ''
wk.register({
["<leader>m"] = {
name = "Metals",
w = { "<cmd>lua require'metals'.worksheet_hover()<CR>", "Worksheet hover" },
d = { "<cmd>lua require'metals'.open_all_diagnostics()<CR>", "Open all diagnostics" },
},
})
''}
''}
${writeIf cfg.rust.enable ''
-- Rust config
Expand Down
11 changes: 11 additions & 0 deletions modules/lsp/nvim-code-action-menu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.lsp;
keys = config.vim.keys.whichKey;
in
{
options.vim.lsp.nvimCodeActionMenu.enable = mkEnableOption "nvim code action menu";
Expand All @@ -17,5 +18,15 @@ in
vim.nnoremap = {
"<silent><leader>ac" = "<cmd> CodeActionMenu<CR>";
};

vim.luaConfigRC = ''
${writeIf keys.enable ''
wk.register({
["<leader>a"] = {
name = "Code actions",
},
})
''}
'';
};
}
11 changes: 10 additions & 1 deletion modules/lsp/trouble.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.lsp;
keys = config.vim.keys.whichKey;
in
{
options.vim.lsp.trouble.enable = mkEnableOption "trouble diagnostics viewer";
Expand All @@ -13,17 +14,25 @@ in
vim.startPlugins = with pkgs.neovimPlugins; [ trouble ];

vim.nnoremap = {
"<leader>xx" = "<cmd> TroubleToggle<CR>";
"<leader>lwd" = "<cmd> TroubleToggle workspace_diagnostics<CR>";
"<leader>ld" = "<cmd> TroubleToggle document_diagnostics<CR>";
"<leader>lr" = "<cmd> TroubleToggle lsp_references<CR>";
"<leader>xx" = "<cmd> TroubleToggle<CR>";
"<leader>xq" = "<cmd> TroubleToggle quickfix<CR>";
"<leader>xl" = "<cmd> TroubleToggle loclist<CR>";
};

vim.luaConfigRC = ''
-- Enable trouble diagnostics viewer
require("trouble").setup {}
${writeIf keys.enable ''
wk.register({
["<leader>x"] = {
name = "Troubles",
},
})
''}
'';
};
}
2 changes: 1 addition & 1 deletion modules/neoclip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in
vim.startPlugins = [ pkgs.neovimPlugins.nvim-neoclip ];

vim.nnoremap = {
"<leader>nc" = "<cmd> Telescope neoclip unnamed extra=star,plus<CR>";
"<leader>fnc" = "<cmd> Telescope neoclip unnamed extra=star,plus<CR>";
};

vim.luaConfigRC = ''
Expand Down
9 changes: 9 additions & 0 deletions modules/tabline/nvim-bufferline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.tabline.nvimBufferline;
keys = config.vim.keys.whichKey;
in
{
options.vim.tabline.nvimBufferline = {
Expand Down Expand Up @@ -94,6 +95,14 @@ in
end,
}
}
${writeIf keys.enable ''
wk.register({
["<leader>b"] = {
name = "Buffers",
},
})
''}
'';
}
);
Expand Down
9 changes: 9 additions & 0 deletions modules/telescope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with builtins;

let
cfg = config.vim.telescope;
keys = config.vim.keys.whichKey;
in
{
options.vim.telescope = {
Expand Down Expand Up @@ -80,6 +81,14 @@ in
})
''}
${writeIf keys.enable ''
wk.register({
["<leader>f"] = {
name = "Telescope",
},
})
''}
require("telescope").setup {
defaults = {
vimgrep_arguments = {
Expand Down

0 comments on commit b87a2e5

Please sign in to comment.