feat(nvim): use lazy to load plugins

dev-docs
Moritz Böhme 2023-06-10 21:52:57 +02:00
parent 3204ac12e7
commit 80c38b5120
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
11 changed files with 604 additions and 266 deletions

View File

@ -7,22 +7,207 @@
with lib;
let
cfg = config.my.programs.nvim;
mkPlugin = fileName:
boolToString = bool: if bool then "true" else "false";
quote = str: ''"${toString str}"'';
listToString = list: ''{ ${concatStringsSep ", " (map quote list)} }'';
keybinding =
{ key
, cmd
, func
, mode
, desc
}:
let
path = ./plugins + "/${fileName}";
pluginName = lib.removeSuffix ".lua" fileName;
cmdString =
if cmd != null
then quote cmd
else
(
if func != null
then func
else abort "Either cmd or function must be set"
);
in
''{ ${quote key}, ${cmdString}, mode = ${quote mode}, ${optionalString (desc != null) "desc = ${quote desc},"} }'';
lazySpecFromPlugin =
{ plugin
, dependencies
, init
, conf
, lazy
, event
, enabled
, cmd
, ft
, priority
, keys
}:
''
{
dir = "${plugin}",
name = "${plugin.name}",
lazy = ${boolToString lazy},
enabled = ${boolToString enabled},
dependencies = { ${concatStringsSep ", " (map lazySpecFromPlugin dependencies)} },
${optionalString (init != null)
"init = function(plugin)
${toString init}
end,"
}
${optionalString (conf != null)
"config = function(plugin, opts)
${toString conf}
end,"
}
keys = { ${concatStringsSep ",\n" (map keybinding keys)} },
event = ${listToString event},
cmd = ${listToString cmd},
ft = ${listToString ft},
priority = ${toString priority},
}
'';
lazySpecs = concatStringsSep ", " (map lazySpecFromPlugin cfg.plugins);
lazy = ''
require("lazy").setup({
${lazySpecs}
})
'';
in
{
plugin = pkgs.vimPlugins.${pluginName};
type = "lua";
config = lib.readFile path;
imports = [ ./plugins ];
options.my.programs.nvim = {
enable = mkEnableOption "nvim";
plugins = mkOption {
default = [ ];
description = ''
List of plugins with config.
'';
type = with types; listOf (
let
sub = submodule {
options = {
conf = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to be executed when the plugin is loaded.
'';
};
dependencies = mkOption {
type = listOf sub;
default = [ ];
description = ''
List of plugins this plugin depends on.
'';
};
init = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to be executed when the plugin is initialized.
'';
};
event = mkOption {
type = listOf str;
default = [ ];
description = ''
Event to load the plugin on.
'';
};
lazy = mkOption {
type = bool;
default = false;
description = ''
Whether to load the plugin lazily.
'';
};
plugin = mkOption {
type = package;
description = ''
The plugin package.
'';
};
enabled = mkOption {
type = bool;
default = true;
description = ''
Whether to enable the plugin.
'';
};
cmd = mkOption {
type = listOf str;
default = [ ];
description = ''
Command to load the plugin.
'';
};
ft = mkOption {
type = listOf str;
default = [ ];
description = ''
Filetype to load the plugin on.
'';
};
priority = mkOption {
type = int;
default = 50;
description = ''
Priority to load the plugin.
'';
};
keys = mkOption {
default = [ ];
description = ''
List of keybindings.
'';
type = listOf (submodule {
options = {
key = mkOption {
type = str;
description = ''
Key to bind.
'';
};
cmd = mkOption {
type = nullOr str;
default = null;
description = ''
Command to execute.
'';
};
func = mkOption {
type = nullOr str;
default = null;
description = ''
Function to execute.
'';
};
mode = mkOption {
type = str;
default = "n";
description = ''
Mode to bind the key in.
'';
};
desc = mkOption {
type = nullOr str;
default = null;
description = ''
Description of the keybinding.
'';
};
};
});
};
};
};
pluginFileNames = builtins.attrNames (builtins.readDir ./plugins);
pluginsWithConfig = builtins.map mkPlugin pluginFileNames;
in
{
options.my.programs.nvim.enable = mkEnableOption "nvim";
sub
);
};
};
config = mkIf cfg.enable {
home-manager.users.moritz = {
@ -41,11 +226,7 @@ in
vimdiffAlias = true;
withNodeJs = true;
withPython3 = true;
extraLuaConfig = lib.concatLines (
builtins.map
builtins.readFile
[ ./options.lua ./keybinds.lua ./init.lua ]
);
extraLuaConfig = lib.concatLines [ (builtins.readFile ./options.lua) lazy ];
extraPackages = with pkgs; [
alejandra
black
@ -66,30 +247,10 @@ in
yamlfmt
];
plugins = with pkgs.vimPlugins; [
cmp-async-path
cmp-nvim-lsp
cmp_luasnip
copilot-cmp
direnv-vim
friendly-snippets
lsp_lines-nvim
lspkind-nvim
lspsaga-nvim-original
luasnip
nui-nvim
nvim-cmp
nvim-lspconfig
lazy-nvim
nvim-treesitter.withAllGrammars
nvim-ufo
nvim-web-devicons
plenary-nvim
popup-nvim
promise-async
vim-fugitive
vim-tmux-navigator
] ++ pluginsWithConfig;
];
};
};
};
}

View File

@ -1,73 +0,0 @@
-- buffer
require("which-key").register({
b = {
name = "buffer",
b = { "<cmd>Telescope buffers<cr>", "List buffers" },
d = { "<cmd>bd<cr>", "Delete buffer" },
},
}, { prefix = "<leader>" })
require("which-key").register({
["["] = {
b = { "<cmd>bprevious<cr>", "Previous buffer" },
},
["]"] = {
b = { "<cmd>bnext<cr>", "Next buffer" },
},
})
-- window
require("which-key").register({
w = {
name = "window",
["|"] = { "<C-w>v", "Split window horizontally" },
["-"] = { "<C-w>s", "Split window vertically" },
w = { "<C-w>w", "Switch window" },
d = { "<C-w>c", "Delete window" },
},
}, { prefix = "<leader>" })
-- tab
require("which-key").register({
["<tab>"] = {
name = "tab",
["<tab>"] = { "<cmd>tabnew<cr>", "New tab" },
n = { "<cmd>tabnext<cr>", "Next tab" },
p = { "<cmd>tabprevious<cr>", "Previous tab" },
d = { "<cmd>tabclose<cr>", "Close tab" },
},
}, { prefix = "<leader>" })
-- file
require("which-key").register({
f = {
name = "file/find",
n = { "<cmd>enew<cr>", "New file" },
},
}, { prefix = "<leader>" })
-- better descriptions for navigation
require("which-key").register({
["<leader>"] = {
f = { name = "file/find" },
g = { name = "git" },
l = { name = "lsp" },
o = { name = "org" },
s = { name = "search" },
t = { name = "toggle" },
x = { name = "diagnostics/quickfix" },
},
["["] = { name = "prev" },
["]"] = { name = "next" },
g = { name = "goto" },
})
-- Clear search with <esc>
require("which-key").register({
["<esc>"] = { "<cmd>noh<cr><esc>", "Escape and clear hlsearch", mode = { "n", "i" } },
})
-- better indenting
require("which-key").register({
["<"] = { "<gv", "Shift left" },
[">"] = { ">gv", "Shift right" },
}, { mode = "v" })

View File

@ -2,10 +2,4 @@ require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
vim.api.nvim_create_autocmd("VimEnter", {
desc = "Disable Copilot by default on startup",
command = "Copilot disable",
})
require("which-key").register({
c = { "<cmd>Copilot toggle<cr>", "Toggle Copilot" },
}, { prefix = "<leader>t" })
vim.cmd("Copilot disable")

View File

@ -0,0 +1,254 @@
{ pkgs, ... }:
with builtins;
{
config.my.programs.nvim.plugins = with pkgs.vimPlugins; [
{
plugin = which-key-nvim;
conf = readFile ./which-key-nvim.lua;
}
{
plugin = catppuccin-nvim;
conf = readFile ./catppuccin-nvim.lua;
priority = 99;
}
{
plugin = formatter-nvim;
lazy = true;
keys = [
{ key = "="; cmd = "<cmd>Format<cr>"; desc = "format (formatter)"; }
];
conf = readFile ./formatter-nvim.lua;
dependencies = [{ plugin = which-key-nvim; lazy = true; }];
}
{
plugin = oil-nvim;
conf = readFile ./oil-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; lazy = true; }
{ plugin = nvim-web-devicons; lazy = true; }
];
}
{
plugin = mini-nvim;
conf = readFile ./mini-nvim.lua;
}
{
plugin = noice-nvim;
conf = readFile ./noice-nvim.lua;
dependencies = [{ plugin = nui-nvim; lazy = true; }];
}
{
plugin = trouble-nvim;
lazy = true;
keys = [
{ key = "<leader>xx"; cmd = "<cmd>TroubleToggle document_diagnostics<cr>"; desc = "Document Diagnostics (Trouble)"; }
{ key = "<leader>xX"; cmd = "<cmd>TroubleToggle workspace_diagnostics<cr>"; desc = "Workspace Diagnostics (Troule)"; }
{ key = "<leader>xl"; cmd = "<cmd>TroubleToggle loclist<cr>"; desc = "Location List (Trouble)"; }
{ key = "<leader>xq"; cmd = "<cmd>TroubleToggle quickfix<cr>"; desc = "Quickfix List (Trouble)"; }
{ key = "<leader>xt"; cmd = "<cmd>TodoTrouble<cr>"; desc = "Todo (Trouble)"; }
{ key = "<leader>xT"; cmd = "<cmd>TodoTrouble keywords=TODO,FIX,FIXME<cr>"; desc = "Todo/Fix/Fixme (Trouble)"; }
{ key = "<leader>st"; cmd = "<cmd>TodoTelescope<cr>"; desc = "Todo"; }
{
key = "[q";
func = ''function()
if require("trouble").is_open() then
require("trouble").previous({ skip_groups = true, jump = true })
else
vim.cmd.cprev()
end
end'';
desc = "Previous trouble/quickfix item";
}
{
key = "]q";
func = ''function()
if require("trouble").is_open() then
require("trouble").next({ skip_groups = true, jump = true })
else
vim.cmd.cnext()
end
end'';
desc = "Next trouble/quickfix item";
}
];
conf = readFile ./trouble-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; }
{ plugin = nvim-web-devicons; lazy = true; }
];
}
{
plugin = nvim-cmp;
conf = readFile ./nvim-cmp.lua;
lazy = true;
event = [ "InsertEnter" ];
dependencies = [
{ plugin = cmp-async-path; }
{ plugin = cmp-nvim-lsp; }
{ plugin = cmp_luasnip; }
{
plugin = copilot-cmp;
dependencies = [
{
plugin = copilot-lua;
conf = readFile ./copilot-lua.lua;
dependencies = [{ plugin = which-key-nvim; }];
}
];
}
{ plugin = friendly-snippets; }
{ plugin = luasnip; lazy = true; }
];
}
{
plugin = todo-comments-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./todo-comments-nvim.lua;
dependencies = [{ plugin = plenary-nvim; lazy = true; }];
}
{
plugin = direnv-vim;
}
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-treesitter.lua;
dependencies = [
{
plugin = orgmode;
lazy = true;
conf = readFile ./orgmode.lua;
}
];
}
{
plugin = nvim-lspconfig;
lazy = true;
event = [ "BufReadPre" "BufNewFile" ];
conf = readFile ./nvim-lspconfig.lua;
dependencies = [
{
plugin = null-ls-nvim;
lazy = true;
conf = readFile ./null-ls-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; lazy = true; }
{ plugin = plenary-nvim; lazy = true; }
];
}
{
plugin = which-key-nvim;
lazy = true;
}
{
plugin = lspkind-nvim;
lazy = true;
}
{
plugin = lsp_lines-nvim;
lazy = true;
}
{
plugin = lspsaga-nvim-original;
lazy = true;
dependencies = [
{ plugin = nvim-web-devicons; lazy = true; }
{ plugin = nvim-treesitter.withAllGrammars; lazy = true; }
];
}
{
plugin = nvim-ufo;
lazy = true;
dependencies = [
{ plugin = promise-async; lazy = true; }
];
}
];
}
{
event = [ "VeryLazy" ];
lazy = true;
plugin = vim-fugitive;
}
{
plugin = vim-tmux-navigator;
}
{
plugin = gitsigns-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./gitsigns-nvim.lua;
dependencies = [{ plugin = which-key-nvim; }];
}
{
plugin = nvim-lastplace;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-lastplace.lua;
}
{
plugin = nvim-treesitter-textsubjects;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-treesitter-textsubjects.lua;
dependencies = [
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
}
];
}
{
plugin = nvim-ts-context-commentstring;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-ts-context-commentstring.lua;
dependencies = [
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
}
];
}
{
plugin = smartcolumn-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./smartcolumn-nvim.lua;
}
{
plugin = telescope-fzf-native-nvim;
conf = readFile ./telescope-fzf-native-nvim.lua;
lazy = true;
keys = [
{ key = "<leader>ff"; cmd = "<cmd>Telescope find_files<cr>"; desc = "Find files"; }
{ key = "<leader>fb"; cmd = "<cmd>Telescope buffers<cr>"; desc = "Find buffers"; }
{ key = "<leader>fr"; cmd = "<cmd>Telescope oldfiles<cr>"; desc = "Find recent files"; }
{ key = "<leader>sl"; cmd = "<cmd>Telescope current_buffer_fuzzy_find<cr>"; desc = "Search lines"; }
{ key = "<leader>sg"; cmd = "<cmd>Telescope live_grep<cr>"; desc = "Live grep"; }
{ key = "<leader>sc"; cmd = "<cmd>Telescope command_history<cr>"; desc = "Command history"; }
{ key = "<leader>sC"; cmd = "<cmd>Telescope commands<cr>"; desc = "Commands"; }
{ key = "<leader>sd"; cmd = "<cmd>Telescope diagnostics<cr>"; desc = "Diagnostics"; }
{ key = "<leader>sh"; cmd = "<cmd>Telescope help_tags<cr>"; desc = "Help tags"; }
{ key = "<leader>sk"; cmd = "<cmd>Telescope keymaps<cr>"; desc = "Keymaps"; }
{ key = "<leader>ss"; cmd = "<cmd>Telescope lsp_document_symbols<cr>"; desc = "Symbols (Document)"; }
{ key = "<leader>sS"; cmd = "<cmd>Telescope lsp_workspace_symbols<cr>"; desc = "Symbols (Workspace)"; }
{ key = "<leader>gc"; cmd = "<cmd>Telescope git_commits<cr>"; desc = "Commits"; }
{ key = "<leader>gs"; cmd = "<cmd>Telescope git_status<cr>"; desc = "Status"; }
];
dependencies = [
{
plugin = telescope-nvim;
lazy = true;
dependencies = [
{ plugin = plenary-nvim; lazy = true; }
{ plugin = which-key-nvim; lazy = true; }
];
}
];
}
];
}

View File

@ -65,7 +65,3 @@ end, {
return languages[vim.bo.filetype] or {}
end,
})
require("which-key").register({
["="] = { "<cmd>Format<cr>", "format (formatter)" },
}, { noremap = true, silent = true })

View File

@ -0,0 +1,63 @@
local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
require("copilot_cmp").setup()
local default_sources = {
{ name = "async_path", priority = 1 },
{ name = "copilot", priority = 2 },
{ name = "luasnip", priority = 2 },
{ name = "nvim_lsp", priority = 3 },
}
cmp.setup({
formatting = {
format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
symbol_map = {
Copilot = "",
},
}),
},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = default_sources,
})
cmp.setup.filetype("org", {
sources = vim.tbl_deep_extend("force", default_sources, {
{ name = "buffer", priority = 1 },
{ name = "orgmode", priority = 3 },
}),
})

View File

@ -1,87 +1,3 @@
vim.loader.enable()
-- Load custom treesitter grammar for org filetype
require("orgmode").setup_ts_grammar()
require("nvim-treesitter.configs").setup({
sync_install = false,
auto_install = false,
highlight = {
enable = true,
-- Required for spellcheck, some LaTex highlights and
-- code block highlights that do not have ts grammar
additional_vim_regex_highlighting = { "org" },
},
})
-- load cmp on InsertEnter
vim.api.nvim_create_autocmd("InsertEnter", {
callback = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
require("copilot_cmp").setup()
local default_sources = {
{ name = "async_path", priority = 1 },
{ name = "copilot", priority = 2 },
{ name = "luasnip", priority = 2 },
{ name = "nvim_lsp", priority = 3 },
}
cmp.setup({
formatting = {
format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
symbol_map = {
Copilot = "",
},
}),
},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = default_sources,
})
cmp.setup.filetype("org", {
sources = vim.tbl_deep_extend("force", default_sources, {
{ name = "buffer", priority = 1 },
{ name = "orgmode", priority = 3 },
}),
})
end,
})
local lsp_lines = require("lsp_lines")
lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines.

View File

@ -0,0 +1,12 @@
-- Load custom treesitter grammar for org filetype
require("orgmode").setup_ts_grammar()
require("nvim-treesitter.configs").setup({
sync_install = false,
auto_install = false,
highlight = {
enable = true,
-- Required for spellcheck, some LaTex highlights and
-- code block highlights that do not have ts grammar
additional_vim_regex_highlighting = { "org" },
},
})

View File

@ -1,22 +0,0 @@
require("which-key").register({
f = {
f = { "<cmd>Telescope find_files<cr>", "Find files" },
b = { "<cmd>Telescope buffers<cr>", "Find buffers" },
r = { "<cmd>Telescope oldfiles<cr>", "Find recent files" },
},
s = {
l = { "<cmd>Telescope current_buffer_fuzzy_find<cr>", "Search lines" },
g = { "<cmd>Telescope live_grep<cr>", "Live grep" },
c = { "<cmd>Telescope command_history<cr>", "Command history" },
C = { "<cmd>Telescope commands<cr>", "Commands" },
d = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
h = { "<cmd>Telescope help_tags<cr>", "Help tags" },
k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Symbols (Document)" },
S = { "<cmd>Telescope lsp_workspace_symbols<cr>", "Symbols (Workspace)" },
},
g = {
c = { "<cmd>Telescope git_commits<cr>", "Commits" },
s = { "<cmd>Telescope git_status<cr>", "Status" },
},
}, { prefix = "<leader>" })

View File

@ -1,38 +1 @@
require("trouble").setup()
require("which-key").register({
x = { "<cmd>TroubleToggle document_diagnostics<cr>", "Document Diagnostics (Trouble)" },
X = { "<cmd>TroubleToggle workspace_diagnostics<cr>", "Workspace Diagnostics (Troule)" },
l = { "<cmd>TroubleToggle loclist<cr>", "Location List (Trouble)" },
q = { "<cmd>TroubleToggle quickfix<cr>", "Quickfix List (Trouble)" },
t = { "<cmd>TodoTrouble<cr>", "Todo (Trouble)" },
T = { "<cmd>TodoTrouble keywords=TODO,FIX,FIXME<cr>", "Todo/Fix/Fixme (Trouble)" },
}, { prefix = "<leader>x" })
require("which-key").register({
t = { "<cmd>TodoTelescope<cr>", "Todo" },
}, { prefix = "<leader>s" })
require("which-key").register({
["["] = {
q = {
function()
if require("trouble").is_open() then
require("trouble").previous({ skip_groups = true, jump = true })
else
vim.cmd.cprev()
end
end,
"Previous trouble/quickfix item",
},
},
["]"] = {
q = {
function()
if require("trouble").is_open() then
require("trouble").next({ skip_groups = true, jump = true })
else
vim.cmd.cnext()
end
end,
"Next trouble/quickfix item",
},
},
})

View File

@ -1,2 +1,76 @@
vim.o.timeout = true
vim.o.timeoutlen = 500
-- buffer
require("which-key").register({
b = {
name = "buffer",
b = { "<cmd>Telescope buffers<cr>", "List buffers" },
d = { "<cmd>bd<cr>", "Delete buffer" },
},
}, { prefix = "<leader>" })
require("which-key").register({
["["] = {
b = { "<cmd>bprevious<cr>", "Previous buffer" },
},
["]"] = {
b = { "<cmd>bnext<cr>", "Next buffer" },
},
})
-- window
require("which-key").register({
w = {
name = "window",
["|"] = { "<C-w>v", "Split window horizontally" },
["-"] = { "<C-w>s", "Split window vertically" },
w = { "<C-w>w", "Switch window" },
d = { "<C-w>c", "Delete window" },
},
}, { prefix = "<leader>" })
-- tab
require("which-key").register({
["<tab>"] = {
name = "tab",
["<tab>"] = { "<cmd>tabnew<cr>", "New tab" },
n = { "<cmd>tabnext<cr>", "Next tab" },
p = { "<cmd>tabprevious<cr>", "Previous tab" },
d = { "<cmd>tabclose<cr>", "Close tab" },
},
}, { prefix = "<leader>" })
-- file
require("which-key").register({
f = {
name = "file/find",
n = { "<cmd>enew<cr>", "New file" },
},
}, { prefix = "<leader>" })
-- better descriptions for navigation
require("which-key").register({
["<leader>"] = {
f = { name = "file/find" },
g = { name = "git" },
l = { name = "lsp" },
o = { name = "org" },
s = { name = "search" },
t = { name = "toggle" },
x = { name = "diagnostics/quickfix" },
},
["["] = { name = "prev" },
["]"] = { name = "next" },
g = { name = "goto" },
})
-- Clear search with <esc>
require("which-key").register({
["<esc>"] = { "<cmd>noh<cr><esc>", "Escape and clear hlsearch", mode = { "n", "i" } },
})
-- better indenting
require("which-key").register({
["<"] = { "<gv", "Shift left" },
[">"] = { ">gv", "Shift right" },
}, { mode = "v" })